JS: Set.prototype.intersection
(new in JS: ECMAScript 2024)
setA.intersection(setB)
-
- return the intersection of 2 sets.
- setB can be a Map.
const xx = new Set([4, 5, 6]) const yy = new Set([6, 7, 8]) console.log(xx.intersection(yy)) // Set(1) { 6 }
// intersection of 2 map's keys const mapA = new Map([[4, 0], [5, 0], [6, 0]]) const mapB = new Map([[6, 0], [7, 0], [8, 0]]) console.log((new Set(mapA.keys())).intersection(mapB)) // Set(1) { 6 }