I have been wonder where a for
loop or a for..in
loop would be farther on an array.
I have tested this using jsperf.
My For
Loop had 16,676,377 op/s
while the for..in
only had 519,853 op/s
So why is:
var a = ["hi", "hi2", "bye", "bye2"];
for (var i in a) {
return a[i];
}
Slower compared to:
var a = ["hi", "hi2", "bye", "bye2"];
for (var i = 0; i < a.length; i++) {
return a[i];
}