Array.each function


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

This function is add 'each' function to the javascript Array object.


Copy this code and paste it in your HTML
  1. if(typeof Array.prototype.each != 'function'){
  2. Array.prototype.each = function(callback, context){
  3. if(this.length > 0 && typeof callback == 'function'){
  4. for(var i = 0; i < this.length; i++){
  5. callback.call(context || window, this[i]);
  6. }
  7. }
  8. }
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.