Nodejs String Starts With startsWith(other, case_cmp)

Here you can find the source of startsWith(other, case_cmp)

Method Source Code

String.prototype.startsWith = function(other, case_cmp) {
  var first  = this;
  var second = other;

  if(!case_cmp) {
    first  = first.toLowerCase();//  w  w  w .  j  a  v a2 s .  c  om
    second = second.toLowerCase();
  }

  return (first.indexOf(second) === 0);
}

Related

  1. startsWith(matchString)
    String.prototype.startsWith = function (matchString) {
        if (this == matchString)
            return true;
        var matchString = '^' + matchString + '[\x20-\x7E]+$';
        var regex = new RegExp(matchString);
        return !!this.match(regex);
    };
    
  2. startsWith(needle)
    String.prototype.startsWith = function(needle) {
        return this.substr(0, needle.length) == needle;
    
  3. startsWith(needle)
    String.prototype.startsWith = function(needle)
        return(this.indexOf(needle) == 0);
    };
    
  4. startsWith(needle)
    String.prototype.startsWith = function(needle) {
        return(this.indexOf(needle) == 0);
    };
    
  5. startsWith(other)
    String.prototype.startsWith = function(other) {
        var length = other.length;
        if (this.length < length)
            return false;
        return this.substring(0, length) == other;
    };
    
  6. startsWith(pattern)
    String.prototype.startsWith = function(pattern) {
      return this.indexOf(pattern) === 0;
    };
    
  7. startsWith(pattern)
    String.prototype.startsWith = function(pattern) {
        return (this.substr(0, pattern.length) == pattern);
    };
    
  8. startsWith(pattern)
    String.prototype.startsWith = function(pattern) {
        return (this.substr(0, pattern.length) === pattern);
    };
    
  9. startsWith(prefix)
    String.prototype.startsWith = function (prefix) {
        return this.indexOf(prefix) === 0;
    String.prototype.endsWith = function (suffix) {
        return this.match(suffix + "$") == suffix;
    };