📌  相关文章
📜  结合 2 个“数组与对象”并删除重复的对象 javascript 代码示例

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

代码示例2
// Join Without Dupes.
const joinWithoutDupes = (A, B) => {
  const a = new Set(A.map(x => x.item))
  const b = new Set(B.map(x => x.item))
  return [...A.filter(x => !b.has(x.item)), ...B.filter(x => !a.has(x.item))]
}

// Proof.
const output = joinWithoutDupes([{item:"apple",description: "lorem"},{item:"peach",description: "impsum"}], [{item:"apple", description: "dolor"},{item:"grape", description: "enum"}])
console.log(output)