Do you think there is a big difference in for…in and for loops? What kind of ‘for’ do you prefer to use and why?
Let’s say we have an array of associative arrays:
var myArray = [{'key': 'value'}, {'key': 'value1'}];
So we can iterate:
for (var i = 0; i < myArray.length; i++)
And:
for (var i in myArray)
I don’t see a big difference. Are there any performance issues?
The choice should be based on the which idiom is best understood.
An array is iterated using:
An object being used as an associative array is iterated using:
Unless you have earth shattering reasons, stick to the established pattern of usage.