Archive

Posts Tagged ‘array’

javascript in_array()

March 10th, 2013 No comments

For those who use the PHP function in_array () here’s how to create this functionality in JavaScript:

Array.prototype.in_array = function(p_val) 
{
  for(var i = 0, l = this.length; i < l; i++) {
    if(this[i] == p_val) return true;
  }
  return false;
}

// example
var v_array = [ 5, 10, 15, 20, 25];
document.writeln(v_array.in_array(10)); // will return 

For details go to original location

Categories: JavaScript Tags: , ,