Javascript String endsWith(searchString, length)

Description

Javascript String endsWith(searchString, length)


String.prototype.endsWith = String.prototype.endsWith || function(searchString, length) {
    length = typeof length === 'number' && length <  this.length && length >= 0 ? length : this.length;
    //from   w w  w  .  ja  v  a 2  s .  com
    return this.substr(length-searchString.length, searchString.length) == searchString;
    
    
    
}

console.log("abcd".endsWith("cd", 3));



PreviousNext

Related