Javascript Array indexOf(item)

Description

Javascript Array indexOf(item)


Array.prototype.indexOf = function(item){
  for (var i = 0; i < this.length; i++) {
    if(this[i] === item) return i;
  };/*from  w  w  w .  ja v  a2s  . c  om*/
  return -1;
};

Javascript Array indexOf(item)

/**/*from w w w.j a  va 2 s .  c  o m*/
 * gets the index of an element in the array. returns -1 if the item is not present
 *
 * @param item - item to look for
 */
Array.prototype.indexOf = function(item) {
  return _indexOf(this, item);
}

Javascript Array indexof(item)

Array.prototype.indexof=function(item){

    var arr=[];/*  w  w w  .java2s . c o m*/
    for(var i=0;i<arr.length;i++){
  if(arr[i]==item){
   arr.push(i);
    }
 }
   return arr;
}

Javascript Array indexOf(item)

Array.prototype.indexOf = function(item) {
 for (var i = 0; i < this.length; i++) {
  if (this[i] === item) {
   return i;/*from  ww  w.ja  va 2s  .  c  o m*/
  }
 }
 return -1;
}



PreviousNext

Related