Skip to content

Instantly share code, notes, and snippets.

@gfranko gfranko/each.js
Created May 16, 2014

Embed
What would you like to do?
.each() JavaScript implementation
function each (collection, callback) {
var x, len;
if(Utils.isArray(collection)) {
x = -1;
len = collection.length;
while(++x < len) {
if (callback(x, collection[x]) === false) {
break;
}
}
} else if(Utils.isPlainObject(collection)) {
for(x in collection) {
if(collection.hasOwnProperty(x)) {
if (callback(x, collection[x]) === false) {
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.