I have stumbled into several methods of looping in JavaScript, what I like the most is:
for(var i = 0; i < a.length; i++){ var element = a[i]; }
Just store the length in a variable first.
var len = a.length; for (var i = 0; i < len; i++) { var element = a[i]; }