Nodejs String Starts With startsWith(needle)

Here you can find the source of startsWith(needle)

Method Source Code

/**// w  w w  . j ava2  s.  c o m
 * Return true if the string starts with the needle passed in argument
 */
String.prototype.startsWith = function(needle) {
    return(this.indexOf(needle) == 0);
};

Related

  1. startsWith()
    const strPro=String.prototype;
    String.prototype.startsWith||Object.assign(strPro,{
      startsWith(searchString,position){
        if (position) {
          return this.indexOf(searchString) === position;
        return this.indexOf(searchString)===0;
      },
      endsWith(searchString,position){
    ...
    
  2. startsWith(e,t)
    String.prototype.startsWith||(String.prototype.startsWith=function(e,t){
         return t=t||0,this.substr(t,e.length)===e}
    );
    
  3. 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);
    };
    
  4. startsWith(needle)
    String.prototype.startsWith = function(needle) {
        return this.substr(0, needle.length) == needle;
    
  5. startsWith(needle)
    String.prototype.startsWith = function(needle)
        return(this.indexOf(needle) == 0);
    };
    
  6. startsWith(other)
    String.prototype.startsWith = function(other) {
        var length = other.length;
        if (this.length < length)
            return false;
        return this.substring(0, length) == other;
    };
    
  7. startsWith(other, case_cmp)
    String.prototype.startsWith = function(other, case_cmp) {
      var first  = this;
      var second = other;
      if(!case_cmp) {
        first  = first.toLowerCase();
        second = second.toLowerCase();
      return (first.indexOf(second) === 0);
    
  8. startsWith(pattern)
    String.prototype.startsWith = function(pattern) {
      return this.indexOf(pattern) === 0;
    };
    
  9. startsWith(pattern)
    String.prototype.startsWith = function(pattern) {
        return (this.substr(0, pattern.length) == pattern);
    };