Javascript Array findIndex(fn)

Description

Javascript Array findIndex(fn)


Array.prototype.findIndex = function(fn) {

 for ( var i = 0; i < this.length; i++ ) {

  if ( fn(this[i]) === true ) {

   return i;//w w  w  . j ava 2s  .  c om

  }
  
 }

  return -1;

};

Javascript Array findIndex(fn)

Array.prototype.findIndex = function(fn) {
  for (var i = 0; i < this.length; i++) {
    if (fn(this[i])){
      return i;//from   w  w  w  . j  a  v  a 2 s  .  c om
    }
  }
  return -1;
}



PreviousNext

Related