JS: String.prototype.endsWith

By Xah Lee. Date: . Last updated: .

New in JS2015.

Return true if str end with searchString. Else, return false.
const xx = "abcd";
console.log(xx.endsWith("b") === false);
str.endsWith(searchString, endPosition)
Use index endPosition as the end of string.

endPosition is negative, count from right.

const xx = "abcd";
console.log(xx.endsWith("cd", 4));
console.log(xx.endsWith("a", 1));
console.log(xx.endsWith("ab", 2));

console.log(xx.endsWith("bc", 2) === false);
BUY ΣJS JavaScript in Depth