1var initialData = [{
2 'ID': 1,
3 'FirstName': 'Sally'
4 },
5 {
6 'ID': 2,
7 'FirstName': 'Jim'
8 },
9 {
10 'ID': 3,
11 'FirstName': 'Bob'
12 }
13];
14
15var newData = [{
16 'ID': 2,
17 'FirstName': 'Jim'
18 },
19 {
20 'ID': 4,
21 'FirstName': 'Tom'
22 },
23 {
24 'ID': 5,
25 'FirstName': 'George'
26 }
27];
28
29var ids = new Set(initialData.map(d => d.ID));
30var merged = [...initialData, ...newData.filter(d => !ids.has(d.ID))];
1// Join Without Dupes.
2const joinWithoutDupes = (A, B) => {
3 const a = new Set(A.map(x => x.item))
4 const b = new Set(B.map(x => x.item))
5 return [...A.filter(x => !b.has(x.item)), ...B.filter(x => !a.has(x.item))]
6}
7
8// Proof.
9const output = joinWithoutDupes([{item:"apple",description: "lorem"},{item:"peach",description: "impsum"}], [{item:"apple", description: "dolor"},{item:"grape", description: "enum"}])
10console.log(output)