- Return value:
- Examples for the above function are provided below:
- Example 2: var str = ‘It is a great day.’ print(str.endsWith(‘great’));
- Example 3: var str = ‘It is a great day.’ print(str.endsWith(‘great’,13));
Here is the syntax of the endsWith() method:
- String.endsWith(searchString [,length])
- const title = ‘Jack and Jill Went Up the Hill’;
- console.log(title.endsWith(‘Up’, 21));
How to check if string ends with in js?
(It may well depend on the JS engine you’re using…) It may well be faster in the matching case, and when the string is small – but when the string is huge it needs to look back through the whole thing even though we don’t really care : ( For checking a single character, finding the length and then using charAt is probably the best way.
What are the parameters of the endswith ( ) method?
Here, the endsWith () method accepts two Attributes or Parameters. string: This is a string Object. substringvalue: It is the set of characters to search for at the end of the given string. This is a mandatory attribute. It can be a single character or multiple characters or multiple words.