Use if statement to check string ends - Node.js String

Node.js examples for String:String End

Description

Use if statement to check string ends

Demo Code

if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(suffix, position) {
        var str = this;
        /*from  www  . j a  v a  2  s. c  om*/
        if (position) {
            str = str.substring(position);
        }
        
        if (str.length < suffix.length) {
            return false;
        }
        
        return str.slice(0 - suffix.length) == suffix;
    };
}

Related Tutorials