Comment on iOS 8 length bug breaks jQuery and Underscore object iterationComments−joeframbach11yThe workaround in the article was: var thingsGroupedById = _.groupBy(things, function(t){ return 'seller' + t.sellerId }); // { seller1: [...], seller2: [...] } But I actually would have failed this in code review: _.map(thingsGroupedById, function (things) { // ... }); and replaced it with: _.map(_.keys(thingsGroupedById), function (thingKey) { var thing = thingsGroupedById[thingKey]; // ... }); because although mapping over objects is "normal", it has never been 100%.−wging11yWhy not instead do _.map(_.values(thingsGroupedById), function(thing) { // operate on thing } Then there's no need to do the property access yourself.Chaining makes this even nicer: _(thingsGroupedById).values().map(function(thing) { }−dandelany11yDepends on what //... is. You might need the key for something, and you can get the value from the key but not vice versa.−gadr90OP11yThis interests me very much. Are there known problems about mapping over objects? What do you mean it has never been 100%? Thanks!−ewang111yThe latest version of underscore has a _.mapObject function.
Comments
The workaround in the article was:
But I actually would have failed this in code review: and replaced it with: because although mapping over objects is "normal", it has never been 100%.Why not instead do
Then there's no need to do the property access yourself.Chaining makes this even nicer:
Depends on what //... is. You might need the key for something, and you can get the value from the key but not vice versa.
This interests me very much. Are there known problems about mapping over objects? What do you mean it has never been 100%? Thanks!
The latest version of underscore has a _.mapObject function.