programming-examples/js/String/Test whether a string ends with a specified string.js

5 lines
225 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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'));