An array of

With the set

Let a = new Set ([1, 2, 3, 4, 5]); Let b = new Set (,2,3,4,5,6,7,8,9 [1]); let arr = Array.from(new Set([...a, ...b])); console.log('arr',arr);Copy the code

Results:,2,3,4,5,6,7,8,9 [1]

Take the intersection

Let a = new Set ([1, 2, 3, 4, 5]); Let b = new Set (,2,3,4,5,6,7,8,9 [1]); let arr = Array.from(new Set([...b].filter(x => a.has(x))));Copy the code

Results: [1, 2, 3, 4, 5]

Take the difference set

Let a = new Set ([1, 2, 3, 4, 5]); Let b = new Set (,2,3,4,5,6,7,8,9 [1]); let arr = Array.from(new Set([...b].filter(x => ! a.has(x)))); console.log('arr',arr);Copy the code

Results:,7,8,9 [6]

The array object

Take the intersection


let a=[{id:1,a:123,b:1234},{id:2,a:123,b:1234}];
let b=[{id:1,a:123,b:1234},{id:2,a:123,b:1234},{id:3,a:123,b:1234},{id:4,a:123,b:1234}];
let arr = [...b].filter(x => [...a].some(y => y.id === x.id));
console.log('arr',arr)
Copy the code

Results:

[{id:1,a:123,b:1234},{id:2,a:123,b:1234}]
Copy the code

Take the difference set

let a=[{id:1,a:123,b:1234},{id:2,a:123,b:1234}]; let b=[{id:1,a:123,b:1234},{id:2,a:123,b:1234},{id:3,a:123,b:1234},{id:4,a:123,b:1234}]; let arr = [...b].filter(x => [...a].every(y => y.id ! == x.id)); console.log('arr',arr);Copy the code

The results of

[{id:3,a:123,b:1234},{id:4,a:123,b:1234}]
Copy the code