I think there must be a question like this before but current search engines cannot give you results to queries of code lines.
My question is:
What's the difference between
for ( var i = 0; i < array.length; i ++ )
console.log(array[i]);
and
for ( var e in array )
console.log(e);
In my case, the first returns 'undefined' or sequence of number, while the second works fine.
for
is significantly faster thanfor...in
; also, for performance reasons, this is a better way of writing the condition:for (var i = 0; l = array.length; i < l; i++)
and finally, if you want to make thefor
loop even more effective, reverse its order:for (var i = items.length; i--;)