Posted By

clapfouine on 02/09/07


Tagged

javascript search array prototype inarray


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
hans


inArray prototype


 / Published in: JavaScript
 

  1. Array.prototype.inArray = function(valeur) {
  2. for (var i in this) { if (this[i] === valeur) return i; }
  3. return -1;
  4. }
  5.  
  6. /*
  7. in_array() renvois la clef si la valeur est présente, sinon, renvoie -1. \\ exemple : \\
  8.  
  9. var t=new Array("coucou","test","plop");
  10. alert( t.in_array("test") ); //affichera 1
  11. alert( t.in_array("bobo") ); //affichera -1
  12. */

Report this snippet  

You need to login to post a comment.