Nodejs String Ends With endsWith(s)

Here you can find the source of endsWith(s)

Method Source Code

String.prototype.endsWith = function(s) {
  return this.length >= s.length && this.substr(this.length - s.length) == s;
}

Related

  1. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
        return (this.substr(this.length - pattern.length, pattern.length) === pattern);
    };
    
  2. endsWith(pattern)
    String.prototype.endsWith = function(pattern) {
        var d = this.length - pattern.length;
        return d >= 0 && this.lastIndexOf(pattern) === d;
    };
    
  3. endsWith(pattern)
    String.prototype.endsWith = String.prototype.endsWith || function ( pattern ) {
        var d = this.length - pattern.length;
        return d >= 0 && this.indexOf(pattern, d) === d;
    
  4. endsWith(pattern, caseSensitive)
    String.prototype.endsWith = function(pattern, caseSensitive) {
      var d, s;
      if (caseSensitive) {
        d = this.length - pattern.length;
        return d >= 0 && this.lastIndexOf(pattern) === d;
      } else {
        s = this.toLowerCase();
        pattern = pattern.toLowerCase();
        d = s.length - pattern.length;
    ...
    
  5. endsWith(prefix)
    String.prototype.endsWith = function(prefix){
        return this.substr(this.length - prefix.length) === prefix;
    };
    
  6. endsWith(s)
    String.prototype.endsWith = function(s){
        return this.indexOf(s) == this.length - s.length;
    };
    
  7. endsWith(s)
    String.prototype.endsWith = function(s){
      var d = this.length - s.length;
      return d >= 0 && this.lastIndexOf(s) === d;
    
  8. endsWith(s)
    String.prototype.endsWith=function(s)
      return this.substring(this.length-s.length)==s;
    };
    
  9. endsWith(s, i)
    String.prototype.endsWith = function(s, i) {
      if(i) { return s.toLowerCase() == this.substring(this.length - s.length).toLowerCase() }
      return s == this.substring(this.length - s.length)
    };