Posted By

surfeurX on 08/25/10


Tagged


Versions (?)

find element in an array


 / Published in: JavaScript
 

  1. Array.prototype.find = function(name, value){
  2. var elem = this;
  3. for(var i=0; i<elem.length; i++){
  4. if(elem[i][name] === value){
  5. return elem[i];
  6. }
  7. }
  8. return null;
  9. }
  10.  
  11. a = [{"a":4, "b":3}, {"n":9, "b":4}]
  12. a.find("b", 4);

Report this snippet  

You need to login to post a comment.