Trying my hand at converting some code:
var data = { 1234: [{ name: "obj1" }], 3456: [{ name: "obj2" }] };
I want it to look like this:
{ 1234: { name: "obj1" }, 3456: { name: "obj2" } }
(single items, not arrays).
I discovered that:
_.mapValues(data, function(arr) { return _.first(arr); })
works perfectly. But I'm puzzled why the following isn't sufficient:
_.mapValues(data, _.first)
Instead, it outputs:
{ 1234: [], 3456: [] }