Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.isSubsetOf

Checks that every value of a set is in another one.

Available since: ES2025

Syntax

setA.isSubsetOf(setB)

Parameters

ParameterTypeDescription
setBSetThe 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
false

Notes

The reverse check is isSupersetOf(), and isDisjointFrom() checks that there are no common values.

See also

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.

Thanks for reading!

Donate to the site — we work hard for you.