Javascript Array in_array(value)

Description

Javascript Array in_array(value)


Array.prototype.in_array = function(value) { 
  for(var n = 0; n < this.length; n++) {
    if (value == this[n]) {
      return true;
    }//  w ww. j a v a  2  s.  c  om
  }
  return false;
}

Javascript Array in_array(value)

Array.prototype.in_array = function (value) {
  return (this.indexOf(value) !== -1);
};

Javascript Array in_array(value)

/**//from  w  ww  .ja  v  a  2 s .  co m
 * Looks if a value can be found inside the array.
 * Returns the index of the item where the value was found.
 * @param value
 * @return integer|false
 */
Array.prototype.in_array = function(value){
    var len = this.length,
        i;
    for(i = 0;i < len;i+=1){
        if(this[i] === value) return i;
    }
    return false;
}



PreviousNext

Related