Check if given string ends with pattern. - Node.js String

Node.js examples for String:String End

Description

Check if given string ends with pattern.

Demo Code


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

Related Tutorials