How can I check if a string ends with a particular character in JavaScript?
Example: I have a string
var str = \"mystring#\";
I wa
From developer.mozilla.org String.prototype.endsWith()
The endsWith()
method determines whether a string ends with the characters of another string, returning true or false as appropriate.
str.endsWith(searchString [, position]);
searchString : The characters to be searched for at the end of this string.
position : Search within this string as if this string were only this long; defaults to this string's actual length, clamped within the range established by this string's length.
This method lets you determine whether or not a string ends with another string.
var str = "To be, or not to be, that is the question.";
alert( str.endsWith("question.") ); // true
alert( str.endsWith("to be") ); // false
alert( str.endsWith("to be", 19) ); // true
ECMAScript Language Specification 6th Edition (ECMA-262)