Stefan Stefan - 7 months ago 7
Javascript Question

How to convert an array of objects to an object in Lodash?

I have this:

[ { list:
[ [Object],
[Object] ] },
{ head:
[ [Object],
[Object] ] }
]


And want to turn it into this:

{ list:
[ [Object],
[Object] ],
head: [ [Object],
[Object] ]
}


So an array of objects into an object. It would be great to achieve this with lodash.

Answer
_.reduce(array, function(memo, current) { return _.extend(memo, current) },  {})