Implement Array search method - Node.js Array

Node.js examples for Array:Search

Description

Implement Array search method

Demo Code


Array.prototype.indexOf = function( value )
{
  for ( var i = 0 ; i < this.length ; i++ )
  {//  ww  w.j  a va 2s  .co  m
    if ( this[i] == value )
      return i ;
  }
  return -1 ;
}

Related Tutorials