underscore js pluck nested key value
javascript, underscore.js
Solution
You can use map like this. Pluck is a refined version of map.
_.map(obj.2014.11, function (item) {
return item.Counts.c
}
This will give you an array with all c values embedded in 11. But I would not be suprised if I have misunderstood your intent...
Problem
I have a JS object like this one ``` var obj = { "2014" : { "11" : { "20" : { "Counts" : { "c" : 2 } }, "21" : { "Counts" : { "c" : 20 } }, "22" : { "Counts" : { "c" : 20 } } } }, "_id" : "53d6883a2dc307560d000004", "createdate" :"2014-11-21T07:15:26.109Z" }; ``` As you can see this is structure which contains year>->month->day->counts->c->value structure I want to pluck out the day and Count(c) values out of it I tried something like this ``` _.pluck(obj,'11') ``` but this is good uptil only month, and doesn't work for days like ``` _pluck(_.pluck(obj,'11'),'20') ```