The endsWith() method determines whether a string ends with the specific character or not, It returns true if the string ends with specific character or string, otherwise returns false.
searchString: A characters or strings to be searched at the end of the string.
position: It is a optional parameters, It indicates that the search within this limit, even if the string is too long, If we can not pass this arguments than it automatically becomes the the length of the string.
This method allow you to determine whether the string is ends with the specific character (sub-string) or not.
The endsWith() method is case-sensitive, it will not ignore the case of the characters.
If client using the old browser and that browser does not support the endsWith() method than you code will not work on that browser so your operation will be terminated, If you check the developer window in old browsers than you get the message like this:
Object doesn't support property or method 'endsWith'
But I created one code for workaround it and it will worked on the all the browsers, I hope it will help you.
The magic of the above code is that if your user accessing the your website with newer browser that support the endsWith() method than the native method is called instead of the our method and if user is using the older browser than the our method is executing, Its magic because the calling of the both method is same.
Explicitly we just add the endsWith() method in the String class if there is not already exist.
Above function will works on the all the older browsers, even with the Internet Explore (IE) browser.
If you want to check that the string have the specific sub-string by ignoring its case, than below code will help you to find out it.
The above code also helps to check you that the string is ends with the specific sub-string or not by ignoring it’s case.