Problem
I need to merge two arrays that are returned from MongoDB by value, however all of the methods I've tried that work with regular javascript arrays aren't working properly. Your help would be greatly appreciated
Arrays
array1 = [ { _id: 5c6c7132f9bf4bdab9c906ff,
user: 5c65d9438e4a834c8e85dd7d },
{ _id: 5c6ccd6d3a0dc4e4951c2bee,
user: 5c65d9438e4a834c8e85dd7e } ]
array2 = users [ { _id: 5c65d9438e4a834c8e85dd7d,
info: { name: 'John', city: 'New York' } },
{ _id: 5c65d9438e4a834c8e85dd7e,
info: { name: 'Paneer', city: 'San Fran' } } ]
Desired Result
mergedArray = [ { _id: 5c6c7132f9bf4bdab9c906ff,
user: 5c65d9438e4a834c8e85dd7d,
info: { name: 'John', city: 'New York' } } ,
{ _id: 5c6ccd6d3a0dc4e4951c2bee,
user: 5c65d9438e4a834c8e85dd7e,
info: { name: 'Paneer', city: 'San Fran' } } ]
What I've tried
- _.merge from lodash
- _.map & _.extend from lodash
- A variety of vanilla javascript .map functions that