Firstly apologies for the load time, I will make the timings based around an action one day, Ok lets keep this simple, there are a few different ways of looping through arrays, lets see which ones perform the best, try this page in the browser of your choice.

Base Array

This will be the array that all loops are going through, lets get the heavy lifting on the array done first:


var loops = 5000000;
var myArray = [];
for (var i=loops; i--;) {
myArray.push(i);
}

For Loop 1


var myValue = 0;
var startTime = new Date().getTime();
for (var i=0;i<myArray.length;i++) {
myValue++;
}
var endTime = new Date().getTime();
var timeDiff = endTime-startTime;
document.getElementById("test1").innerHTML = timeDiff;

 

Total Time to loop:

For Loop 2


var myValue = 0;
var startTime = new Date().getTime();
for (var i=myArray.length; i--;) {
myValue++;
}
var endTime = new Date().getTime();
var timeDiff = endTime-startTime;
document.getElementById("test2").innerHTML = timeDiff;

 

Total Time to loop:

For Loop 3 (For In)


var myValue = 0;
var startTime = new Date().getTime();
for (var x in myArray) {
myValue++;
}
var endTime = new Date().getTime();
var timeDiff = endTime-startTime;
document.getElementById("test3").innerHTML = timeDiff;

 

Total Time to loop:

Conclusion, avoid for in loops through normal arrays, reversing through the array seems slightly more efficient.