Menu

#9 Flaw iterating JS array

open
nobody
None
5
2007-05-22
2007-05-22
Anonymous
No

Iterating JavaScript arrays may not be done using
for (var i in array){...}

It is possible and quite common for other libraries to add functions to the array prototype thus corrupting the iteration.

Instead use
(for var i = 0; i < array.length; i++){
// ... do something with array[i]
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.