Why is using “for…in” with array iteration a bad idea?
The reason is that one construct:
can sometimes be totally different from the other:
Because for...in enumerates through the object that holds the array, not the array itself. If WE add a function to the arrays prototype chain, that will also be included. I.e.
And since we can never be sure that nothing will be added to the prototype chain just use a for loop to enumerate the array:
In addition to the other problems, the "for..in" syntax is probably slower, because the index is a string, not an integer.