Nodejs String Ends With endsWith(needle)

Here you can find the source of endsWith(needle)

Method Source Code

String.prototype.endsWith = function(needle) {
    return this.slice(-needle.length) == needle;
}

Related

  1. endsWith( str )
    String.prototype.endsWith = function( str ) {
        if( str.length > this.length ) {
            return false;
        return( String( this ).substr( this.length - str.length, this.length ) == str );
    };
    
  2. endsWith( value, ignoreCase )
    String.prototype.endsWith = function( value, ignoreCase )
      var L1 = this.length ;
      var L2 = value.length ;
      if ( L2 > L1 )
        return false ;
      if ( ignoreCase )
        var oRegex = new RegExp( value + '$' , 'i' ) ;
    ...
    
  3. endsWith(end)
    String.prototype.endsWith = function(end) {
      return this.indexOf(end) == this.length-end.length;
    };
    
  4. endsWith(end)
    String.prototype.endsWith = function(end) {
        if(end == '') return true;
        else if(end == null || end.length > this.length) return false;
        else return this.indexOf(end, this.length - end.length) !== -1;
    
  5. endsWith(matchstring)
    String.prototype.endsWith = function (matchstring) {
        return reverse(this).startsWith(reverse(matchstring));
    
  6. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
      var d = this.length - pattern.length;
      return d >= 0 && this.lastIndexOf(pattern) === d;
    };
    
  7. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
        return (this.substr(this.length - pattern.length, pattern.length) == pattern);
    };
    
  8. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
        return (this.substr(this.length - pattern.length, pattern.length) === pattern);
    };
    
  9. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
        var d = this.length - pattern.length;
        return d >= 0 && this.lastIndexOf(pattern) === d;
    };