JS: Set.prototype.isSupersetOf

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2024)

setA.isSupersetOf(setB)
  • return true if setA is superset of setB or if they have the same elements.
  • setB can be a Map.
const xx = new Set([4, 5, 6])
const yy = new Set([6])
console.log(xx.isSupersetOf(yy))
// true
const xx = new Set([4, 5])
const yy = new Set([4, 5])
console.log(xx.isSupersetOf(yy))
// true
// isSupersetOf on 2 map's keys

const mapA = new Map([[4, 0], [5, 0], [6, 0]])
const mapB = new Map([[6, 0]])

console.log((new Set(mapA.keys())).isSupersetOf(mapB))
// true

JS set operations