JavaScript or jQuery string ends with utility function

Solution 1:

you could use Regexps, like this:

str.match(/value$/)

which would return true if the string has 'value' at the end of it ($).

Solution 2:

Stolen from prototypejs:

String.prototype.endsWith = function(pattern) {
    var d = this.length - pattern.length;
    return d >= 0 && this.lastIndexOf(pattern) === d;
};

'slaughter'.endsWith('laughter');
// -> true

Solution 3:

Regular expressions

"Hello world".match(/world$/)