Posted By

hERB on 09/16/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Nanobyte
sheedy


in_array()


 / Published in: JavaScript
 

  1. Array.prototype.in_array = function(p_val) {
  2. for(var i = 0, l = this.length; i < l; i++) {
  3. if(this[i] == p_val) {
  4. return true;
  5. }
  6. }
  7. return false;
  8. }
  9.  
  10. // Usage
  11. var foo = ["a", "b"];
  12.  
  13. foo.in_array("a"); // true
  14. foo.in_array("c"); // false

Report this snippet  

You need to login to post a comment.