public
Last active

A simplified forEach loop that's faster than Array.forEach

  • Download Gist
fastEach.js
JavaScript
1 2 3 4 5 6
function fastEach(items, callback) {
for (var i = 0; i < items.length && !callback(items[i], i, items);i++) {}
return items;
}
 
module.exports = fastEach;

Any value in caching the items length? This is sometimes recommend in performance optimisations. Difference will be minimal, but still, you don't want somebody making a fastereach module ;)

for (var i = 0, count = items.length; i < count && !callback(items[i], i, items);i++) {}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.