Posted By

iamarcel on 11/04/11


Tagged

javascript array index Value callback each


Versions (?)

Array.each()


 / Published in: JavaScript
 

There you go, a simple implementation of a method to loop trough your JavaScript arrays. I am by no means an expert of Javascript, but I tried to make it as fast and short (in terms of amount of characters ;) ) as possible.

  1. /* Array.each( callback(index, value) );
  2. / You can also refer to "this" inside your function, which will refer to your array. */
  3. Array.prototype.each=function(c){var a=this,l=a.length,i;for(i=0;i<l;i++){c.call(a,i,a[i]);}};

Report this snippet  

You need to login to post a comment.