programming-examples/js/String/Test whether a string ends with a specified string.js
2019-11-15 12:59:38 +01:00

5 lines
225 B
JavaScript

function endsWith(input, string) {
var index = input.length - string.length;
return index >= 0 && input.indexOf(string, index) > -1;
}
console.log(endsWith('JS string exercises', 'exercises'));