This isn't the right way to loop over arrays in JS. Just do:

for (var i = 0; i < a.length; i++) {
}