check if string ends with value code example
Example 1: javascript check if string ends with
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
Example 2: regex ends with string
$ is used to match the end of the string. and can be used like
"string"$
like
xyz$
if you want to end with xzy