inArray prototype


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.