Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Set.prototype.isSupersetOf — testing for a superset

The isSupersetOf() method checks whether a Set contains every element of another set-like collection. It returns a boolean; equal sets also satisfy the condition, so this is not a proper-superset test.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

set.isSupersetOf(other)

set.isSupersetOf(other) returns true when set contains every element of other, and false otherwise. Equal sets qualify, and every set is a superset of an empty Set. The method itself does not mutate the sets.

The receiver set must be an actual Set object; merely providing similar methods is insufficient. The argument other can be a set-like object: it exposes a size property and callable has() and keys() methods. The method coerces size to a number, rejects NaN, truncates finite values toward zero, and then rejects a negative result. For example, the string "1" is accepted as a size of 1. Both Set and Map qualify — a Map contributes its keys. A plain array does not meet this contract; use new Set(array).

After validating the argument, the method returns false if the receiver's size is smaller than the size of other. Otherwise, it iterates over other.keys() and stops at the first missing element. other.has() must exist but is not called by this algorithm. Membership follows SameValueZero semantics: NaN matches NaN, +0 and -0 are equivalent, and objects are compared by identity. Custom getters and iterators can execute code with side effects.

The method is part of ECMAScript 2025. The language specification does not establish support in a particular browser; check typeof Set.prototype.isSupersetOf === 'function' in the target runtime before use. The Node version used in a repository does not prove browser support.

Examples

const available = new Set(['read', 'write', 'share']);
const required = new Set(['read', 'write']);

console.log(available.isSupersetOf(required));
console.log(required.isSupersetOf(available));
console.log(available.isSupersetOf(available));
console.log(available.isSupersetOf(new Set()));

Result

true
false
true
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources