Skip to content

Instantly share code, notes, and snippets.

@colynb
Created August 7, 2012 22:36
Show Gist options
  • Save colynb/3290105 to your computer and use it in GitHub Desktop.
Save colynb/3290105 to your computer and use it in GitHub Desktop.
Native Array foreach implementation
Array.prototype.foreach = function(action) {
for (var i = 0; i < this.length; i++) {
action(i, this[i]);
}
};
​var arr = [1,2,3,4];
arr.foreach(function(i,item){
$('#log').append('<p>'+item+'</p>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment