JavaScript
Article
By Sam Deering

Speed Question jQuery.each vs. for loop

By Sam Deering

Quick point. It might be beneficial to mention that we are using vanilla for loops instead of jQuery.each for speed (up to 84% faster). Using a for loop with variable caching produces even faster results jsperf – each vs for.

each-vs-for-speed-js-perf

--ADVERTISEMENT--

jQuery.each

$.each(a, function() {
  e = this;
});

For Loop with Caching

for ( var i = 0, len = a.length; i For Loop without Caching

for (var i = 0; i Pre-calculated Length attempt

precalculated-length

var len = a.length, i = 0;
for (i; i

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.