Javascritp foreach

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

I saw a lot of bad javascritp foreach examples ... so here is the best solution. See the link (german) for another snippet to iterate over object properties via foreach.

Copy this code and paste it in your HTML
  1. Array.prototype.foreach = function(callback) {
  2. for(var k=0; k<this.length; k++) {
  3. callback(k, this[k]);
  4. }
  5. }


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.