Iterate over an object and an array
Fri May 21 2021 21:57:09 GMT+0000 (UTC)
Saved by
@ejiwen
#javascript
_.each = function(collection, iterator) {
if (Array.isArray(collection)) {
for (var i = 0; i < collection.length; i++) {
iterator(collection[i], i, collection);
}
} else {
for (var property in collection) {
iterator(collection[property], property, collection);
}
}
};
content_copyCOPY
Comments