I have two collections, and the objects have a common key \"userId\". As below:
var _= require(\'lodash\');
var a = [
{ userId:\"p1\", item:1},
{ userId
ES6+ version without lodash.
const array1 = [{ userId: "p1", item: 1 }, { userId: "p2", item: 2 },{ userId: "p3", item: 4 }];
const array2 = [{ userId: "p1", profile: 1 }, { userId: "p2", profile: 2 }];
const result = array1.map(a => ({
...a,
...array2.find(b => b.userId === a.userId) // _.find(array2, 'skuId') <-- or with lodash
}));
document.write('' + JSON.stringify(result, 0, 2) + '
');