Question

This works, but how can I chain it?...

allWeeks = _.flatten(_.pluck(dates.months, 'weeks'))
allDays  = _.flatten(_.pluck(allWeeks, 'days'))

I've tried:

allDays = _.chain(dates.months).pluck('weeks').flatten().pluck('days').flatten()

And this:

allDays = _(dates.months).pluck('weeks').flatten().pluck('days').flatten()
Was it helpful?

Solution

Instead of deleting this question out of sheer embarrassment, I will leave the answer here for any other poor schmuck out there wondering "why the heck isn't my lodash chain working?!":

You must end the chain with .value()

so this:

allDays = _.chain(dates.months).pluck('weeks').flatten().pluck('days').flatten().value()

and this:

allDays = _(dates.months).pluck('weeks').flatten().pluck('days').flatten().value()

OTHER TIPS

You have to know that starting for Lodash 4.0.0, _.pluck() is replaced by _.map() so for example:

var objects = [{ 'a': 1 }, { 'a': 2 }];

// in 3.10.1
_.pluck(objects, 'a'); // → [1, 2]
_.map(objects, 'a'); // → [1, 2]

// in 4.0.0
_.map(objects, 'a'); // → [1, 2]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top