Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 610
Stefan Avatar asked May 13 '15 17:05

Stefan


1 Answers

I think an even shorter solution would be:

Object.assign({}, ...array)

I know you asked for lodash, but it doesn't seem like you even need this way. Unless you want to use _.extend.

like image 54
iamricard Avatar answered Sep 23 '22 14:09

iamricard