Skip to content

@KoryNunn /fastEach.js
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A simplified forEach loop that's faster than Array.forEach
function fastEach(items, callback) {
for (var i = 0; i < items.length && !callback(items[i], i, items);i++) {}
return items;
}
module.exports = fastEach;
@DamonOehlman

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++) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.