![]() |
VOOZH | about |
JavaScript String startsWith() method checks if a string starts with the characters of a specified string.
str.startsWith( searchString , position )This method accepts two parameters as mentioned above and described below:
This method returns the Boolean value true if the searchString is found else returns false.
The function checks if the string 'str' starts with the substring 'Gee'. It returns true because 'Geeks for Geeks' starts with 'Gee'.
The function checks if the string 'str' starts with the substring 'great' starting from index 8. It returns true because 'great day.' starts at index 8 in the string.
The code checks if the URL starts with "https://" and if the filename starts with ".js". It returns true for the URL starting with "https://" and false for the filename starting with ".js".
We have a complete list of Javascript String Methods, to check those please go through the Javascript String Complete Reference article.