JavaScript string startsWith() method
The string.startsWith(searchString, index) method is used to check if the given string starts with the specified string's characters. The startsWith() method is case-sensitive.
Where:
- searchString: the string or character to search for. If the search string is a RegExp, a TypeError is raised
- index (optional): the index from which to search (default value is 0)
How to check if a string ends with a specified string?
To check if the end of a string is the same as a specified string, use the string.endsWith(searchString, length) method. The endsWith() method is case-sensitive.
Where:
- searchString: the string or character to search for. If the search string is a RegExp, a TypeError is raised.
- length (optional): The length of the string to search for (the default value is the length of the given string). If the value is greater than the search string's length, then the search is carried out over the entire string; if it is less than the given string, it will be cut to the specified length. The method will return "false" if a negative value is specified.