Nodejs String Starts With startsWith()

Here you can find the source of startsWith()

Method Source Code

const strPro=String.prototype;

String.prototype.startsWith||Object.assign(strPro,{
   startsWith(searchString,position){/* www.j  a  v a 2 s . com*/
      if (position) {
         return this.indexOf(searchString) === position;
      }
      
      return this.indexOf(searchString)===0;
   },
   endsWith(searchString,position){
      if (position) {
         const sStr=this.substring(0,position);
         
         return this.lastIndexOf(sStr)===(sStr.length-position.length);
      }
      
      return this.lastIndexOf(searchString)===this.length-searchString.length;
   }
});

Related

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