Skip to content

Conversation

@lukas-shawford
Copy link

I see a couple pull requests fixing the same issue with array iteration when the array prototype has been extended (#2, #7), so I thought I'd open another one :-)

I think this fix is simplest - just use a regular for loop instead of for..in. The trouble with for..in is it doesn't guarantee iteration order, and it also picks up inherited properties. For these reasons, it is generally not recommended to use for..in for iterating over an array.

I see the other pull requests addressed this issue either by either checking the type to ensure it's not a function, or using hasOwnProperty, but I think this method is the simplest - it's what a for loop is for!

@viki53
Copy link

viki53 commented Jul 11, 2016

👍

I was just about to do the same PR, this was really annoying and a waste of time to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants