JS: String.prototype.endsWith
(new in ECMAScript 2015)
str.endsWith(searchString)-
Return
trueif str end with searchString. Else, returnfalse.const xx = "abcd"; console.log(xx.endsWith("cd")); 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);