Set.prototype.isSubsetOf
Checks that every value of a set is in another one.
Available since: ES2025
Syntax
setA.isSubsetOf(setB)Parameters
| Parameter | Type | Description |
|---|---|---|
| setB | Set | The set to compare with. |
Return value
booleantrue if every value of the first set is in the second.
Examples
Does the user have all the required permissions:
const required = new Set(['read', 'write']);
const granted = new Set(['read', 'write', 'delete']);
console.log(required.isSubsetOf(granted));
console.log(granted.isSubsetOf(required));Output:
true
falseNotes
The reverse check is isSupersetOf(), and isDisjointFrom() checks that there are no common values.
See also
- Set.prototype.difference — Returns the values that are only in the first set.
- Array.prototype.every — Checks that every element of an array passes a test.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.