To get the intersection of two Sets in JavaScript, combine the filter() and has() array methods: const set1 = new Set([1, 2, 3, 4, 5]);
const set2 = new Set([4, 5, 6, 7, 8]);
const intersection = new Set([...set1].filter(x => set2.has(x)));
console.log(intersection); // Set {4, 5} The Array filter() method…