JavaScript: String.prototype.endsWith
New in JS2015.
str.endsWith(searchString)
-
Return
true
if str end with searchString. Else, returnfalse
. str.endsWith(searchString, endPosition)
- Use index endPosition as the end of string.
endPosition is negative, count from right.
const ss = "abcd"; console.log( ss.endsWith("cd") ); // true console.log( ss.endsWith("cd", 4) ); // true console.log( ss.endsWith("a", 1) ); // true console.log( ss.endsWith("ab", 2) ); // true console.log( ss.endsWith("b") ); // false console.log( ss.endsWith("bc", 2) ); // false