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

_.each fails with objects with a length key #252

Closed
jeffv opened this issue Jul 19, 2011 · 2 comments
Closed

_.each fails with objects with a length key #252

jeffv opened this issue Jul 19, 2011 · 2 comments

Comments

@jeffv
Copy link

jeffv commented Jul 19, 2011

var _ = require('underscore');

banana = {
length: 999
}

_.each(banana, function(val) {
console.log('Got Here'); //fails
})

If banana.length is a string, rather then an integer, it suddenly works. When I did I search I saw a long discussion on this subject back in march. Any head way made? This really surprised me when I came across it. There's nothing in the documentation saying this is a failure case when foreaching over an object.

I have a situation where I can't rename the key so I've had to ditch underscore temporarily.

@michaelficarra
Copy link
Collaborator

See 5eaf71f, 942d6312, and 727db393 for the recent change that affected this. Still, an object with a numeric length value was treated as an array by _.each before then. That was decided long before those commits, and it's a decision I support.

@jashkenas
Copy link
Owner

This is a dup of #154 and #148 ... I've added a paragraph about it to the documentation -- see the above commit.

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

No branches or pull requests

3 participants