Search code examples
javascriptarraysobjectlodash

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.


Solution

  • _.reduce(array, function(memo, current) { return _.assign(memo, current) },  {})