Find in a string - Node.js String

Node.js examples for String:String Value

Description

Find in a string

Demo Code


define( function() {

  Array.prototype.find = function( f ) {
    for ( var i = 0, n = this.length; i < n; i++ ) {
      if ( f( this[ i ], i ) ) return this[ i ];
    }/*from  w  w w  . j  ava2 s. co  m*/
    return false;
  };

  Array.prototype.findReverse = function( f ) {
    for ( var i = this.length; i--; ) {
      if ( f( this[ i ], i ) ) return this[ i ];
    }
    return false;
  };

} );

Related Tutorials