how to find out what a string ends with in javascript

JavaScript
"Hello world".endsWith("world");//true
"Hello world".endsWith("Hello");//falsefunction solution(str, ending){
  return str.indexOf(ending, str.length - ending.length) !== -1;
}function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

endsWith("hello young man","man");//true
endsWith("hello young man","boy");//false
function isJS(path) {
	return /jsx?$/.test(path)
}
Source

Also in JavaScript: