Nodejs String Starts With startWith(text)

Here you can find the source of startWith(text)

Method Source Code

String.prototype.startWith = function (text) {
    return this.indexOf(text) == 0;
};

var msg = "Hello world!";
console.log(msg.startWith("Hello"));

Related

  1. startWith(str)
    String.prototype.startWith = function(str) {
      var result = true;
      if (typeof(str)=='string' && str.length <= this.length) {
        for (var i=0,len=str.length;i<len;i++) {
          if (str.charAt(i) == this.charAt(i)) {
            continue;
          } else {
            result = false;
            break;
    ...
    
  2. startWith(str)
    String.prototype.startWith = function(str) {
      var reg = new RegExp("^" + str);
      return reg.test(this);
    };
    String.prototype.endWith = function(str) {
      var reg = new RegExp(str + "$");
      return reg.test(this);
    };
    
  3. startWith(str)
    String.prototype.startWith=function(str){     
      var reg=new RegExp("^"+str);     
      return reg.test(this);        
    String.prototype.endWith=function(str){     
      var reg=new RegExp(str+"$");     
      return reg.test(this);        
    
  4. startWith(str)
    String.prototype.startWith=function(str){  
        if(str==null||str==""||this.length==0||str.length>this.length)  
          return false;  
        if(this.substr(0,str.length)==str)  
          return true;  
        else  
          return false;  
        return true;  
    };
    ...
    
  5. startWith(substr)
    String.prototype.startWith = function(substr) {
        return this.indexOf(substr) == 0;
    };
    
  6. startWithVowel()
    String.prototype.startWithVowel = function () {
        return this.charAt(0).toLowerCase().isVowel();
    };
    String.prototype.isVowel = function () {
        var vowels = ['a', 'e', 'i', 'o', 'u'];
        return vowels.indexOf(this.toLowerCase()) != -1;
    };
    
  7. beginsWith( str )
    String.prototype.beginsWith = function( str ) {
        return this.substr( 0, str.length ) == str;
    };
    
  8. beginsWith(s)
    String.prototype.beginsWith = function(s){
        return this.indexOf(s) == 0;
    };
    
  9. beginsWith(s)
    String.prototype.beginsWith= function(s)
        return s===this.substring(0, s.length);
    if (!String.prototype.localeCompare)
        String.prototype.localeCompare = function(other)
            if (this < other)
                return -1;
    ...