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

18 lines
523 B
JavaScript

function string_endsWith(str, suffix)
{
if (((str===null) || (str==='')) || ((suffix===null) || (suffix==='')))
{
return false;
}
else
{
str = str.toString();
suffix = suffix.toString();
}
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
console.log(string_endsWith('JS PHP PYTHON','PYTHON'));
console.log(string_endsWith('JS PHP PYTHON',''));