1const arr1 = [{ id: 1 }, { id: 2 }]
2const arr2 = [{ id: 1 }, { id: 3 }]
3const intersection = arr1.filter(item1 => arr2.some(item2 => item1.id === item2.id))
4// intersection => [{ id: 1 }]
1const intersection = (a, b) => {
2 b = new Set(b); // recycling variable
3 return [...new Set(a)].filter(e => b.has(e));
4};
5
6console.log(intersection([1, 2, 3, 1, 1], [1, 2, 4])); // Array [ 1, 2 ]