Javascript Array indexOf(searchElement, fromIndex)

Description

Javascript Array indexOf(searchElement, fromIndex)


Array.prototype.indexOf = function(searchElement, fromIndex) {
  if (!fromIndex || !isFinite(fromIndex)) {
    fromIndex = 0;/*from w w  w . ja v  a2 s. com*/
  }

  for (var i = fromIndex, l = this.length; i < l; ++i) {
    if (this.hasOwnProperty(i) && this[i] === searchElement) {
      return i;
    }
  }
  return -1;
}

Javascript Array indexOf(searchElement, fromIndex)

Array.prototype.indexOf = function(searchElement, fromIndex){
 var i/*from  w w  w .j av  a 2 s. c o m*/
 for (i = fromIndex || 0; i <this.length && this[i] !== searchElement; i++);
 i = i>=this.length? null: i
 return i
}



PreviousNext

Related