Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use for loop instead of for in #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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