Nodejs String Starts With startsWith(matchString)

Here you can find the source of startsWith(matchString)

Method Source Code

String.prototype.startsWith = function (matchString) {
    //if exact match return true
    if (this == matchString)
        return true;
    //  w ww  .ja v  a  2 s.  co  m
    var matchString = '^' + matchString + '[\x20-\x7E]+$';
        
    var regex = new RegExp(matchString);
    return !!this.match(regex);
};

Related

  1. startsWith( pattern )
    String.prototype.startsWith = String.prototype.startsWith || function ( pattern ) {
        return this.lastIndexOf(pattern, 0) === 0;
    
  2. startsWith( str )
    String.prototype.startsWith = function( str ) {
        if ( str.length > this.length ) {
            return false;
        return( String( this ).substr( 0, str.length ) == str );
    };
    
  3. startsWith( value )
    String.prototype.startsWith = function( value )
      return ( this.substr( 0, value.length ) == value ) ;
    
  4. 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){
    ...
    
  5. startsWith(e,t)
    String.prototype.startsWith||(String.prototype.startsWith=function(e,t){
         return t=t||0,this.substr(t,e.length)===e}
    );
    
  6. startsWith(needle)
    String.prototype.startsWith = function(needle) {
        return this.substr(0, needle.length) == needle;
    
  7. startsWith(needle)
    String.prototype.startsWith = function(needle)
        return(this.indexOf(needle) == 0);
    };
    
  8. startsWith(needle)
    String.prototype.startsWith = function(needle) {
        return(this.indexOf(needle) == 0);
    };
    
  9. startsWith(other)
    String.prototype.startsWith = function(other) {
        var length = other.length;
        if (this.length < length)
            return false;
        return this.substring(0, length) == other;
    };