📌  相关文章
📜  如何使用 lodash 通过相同的键合并 2 个对象数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:21.481000             🧑  作者: Mango

代码示例1
Lodash
var a = [
  { userId:"p1", item:1},
  { userId:"p2", item:2},
  { userId:"p3", item:4}
];

var b = [
  { userId:"p1", profile:1},
  { userId:"p2", profile:2},
  { userId:"p4", profile:4}
];
var merged = _.merge(_.keyBy(a, 'userId'), _.keyBy(b, 'userId'));
var values = _.values(merged);
console.log(values);