str.startsWith( searchString , position )
Parameters: This method accepts two parameters as mentioned above and described below:
- searchString: It is a required parameter. It stores the string which needs to search.
- start: It determines the position in the given string from where the searchString is to be searched. The default value is zero.
Return value This method returns the Boolean value true if the searchString is found else returns false.
Example 1: Below is the example of the String startsWith() Method
Example 2: In the above example, the method startsWith() checks whether the string str starts with It or not. Since the string starts with It therefore it returns true.
Example 3: In this example, the method startsWith() checks whether the string str starts with great or not. Since great appears in the middle and not at the beginning of the string therefore it returns false.
Example 4: In this example, the method startsWith() checks whether the string str starts with great or not at the specified index 8. Since great appears at the given index in the string therefore it returns true.
- Chrome 41 and above
- Edge 12 and above
- Opera 28 and above
- Firefox 17 and above
- Safari 9 and above
Please Login to comment...