JavaScript Set isSubsetOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

set.isSubsetOf(other) checks whether every value of set is also in other. It returns true if nothing in the first Set is missing from the second, and false if even one value is missing.

Think of it as "is my list fully covered by that list?" The method returns only a boolean. It does not create a new Set and does not change either Set. The argument must be a Set or a set-like object such as a Map.

Remember
small.isSubsetOf(big)

every value of small is in big  → true
one value of small is missing   → false

An empty Set is a subset of every Set
A Set is a subset of itself
Direction matters: ask the smaller Set

Syntax

Call it on the Set you want to test, and pass the bigger Set. Use the boolean in an if statement.

JavaScript
const needed = new Set(["html", "css"]);
const known = new Set(["html", "css", "js"]);

console.log(needed.isSubsetOf(known));   // true
console.log(known.isSubsetOf(needed));   // false
CallWhat it does
a.isSubsetOf(b)true if every value of a is in b.
b.isSupersetOf(a)The same question asked from the bigger Set.
a.difference(b).size === 0The same check, but it builds a whole new Set first.
a.isSubsetOf(map)A Map works as the argument, and its keys are compared.

A standard JavaScript method (ES2025) on every Set, from Set.prototype. It works in current browsers and in Node.js 22 or newer. Siblings: add(), clear(), delete(), difference(), entries(), forEach(), has(), intersection(), isDisjointFrom(), isSupersetOf(), keys(), symmetricDifference(), union(), values(), [Symbol.iterator]().

Library declarations
JavaScript
// ECMAScript 2025
Set.prototype.isSubsetOf(other)

// other  : a Set, or a set-like object (needs size, has() and keys())
// returns: true or false
// throws : TypeError if other is not set-like (for example an array)

Parameters

ParameterDescription
otherRequired. A Set, or any set-like object: an object with a numeric size and the methods has() and keys(). A Map is set-like. An array is not, so convert it with new Set(array).

Return Value

Return ValueDescription
trueEvery value of the Set is also in other. This includes the case of two equal Sets, and the case of an empty Set.
falseAt least one value of the Set is missing from other.
TypeError (thrown)other is not set-like, for example an array or a number.

JavaScript Examples

Example 1 — Check Whether a Set Is Covered

A job needs two skills. Check if a candidate knows all of them, in both directions.

JavaScript
const needed = new Set(["html", "css"]);
const known = new Set(["html", "css", "js"]);
const partial = new Set(["html", "python"]);

console.log("needed in known: " + needed.isSubsetOf(known));
console.log("needed in partial: " + needed.isSubsetOf(partial));
console.log("known in needed: " + known.isSubsetOf(needed));
Try It Yourself

The Try It page first checks that Set.prototype.isSubsetOf() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. Fully covered. Both html and css are in known, so needed.isSubsetOf(known) is true.
  2. Missing one. partial has html but not css, so the answer is false.
  3. Opposite direction. known has js, which needed does not have, so known.isSubsetOf(needed) is false.

Example 2 — Equal and Empty Sets

Two special cases: a Set and its copy, and an empty Set. Then check how a strict subset can be tested.

JavaScript
const a = new Set([1, 2, 3]);
const copy = new Set([1, 2, 3]);

console.log("Same values: " + a.isSubsetOf(copy));
console.log("Empty Set: " + new Set().isSubsetOf(a));
console.log("Itself: " + a.isSubsetOf(a));

const strict = a.isSubsetOf(copy) && a.size < copy.size;
console.log("Strict subset: " + strict);
Try It Yourself

The Try It page first checks that Set.prototype.isSubsetOf() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. Equal Sets. copy has exactly the same values, so each value of a is found in it. The answer is true.
  2. Empty Set. An empty Set has no value that could be missing, so it is a subset of every Set, and a Set is also a subset of itself.
  3. Strict subset. To require that the other Set has extra values, also compare the sizes. Both sizes are 3, so a.size < copy.size is false.

Example 3 — Check a Checklist and Use a Map

Check that every required step is done. A Map can also be the argument, and its keys are compared.

JavaScript
const required = new Set(["design", "code", "test"]);
const done = new Set(["design", "code"]);

console.log("Ready: " + required.isSubsetOf(done));

done.add("test");
console.log("Ready now: " + required.isSubsetOf(done));

const status = new Map([["design", true], ["code", true], ["test", false], ["docs", false]]);
console.log("Keys of the Map cover it: " + required.isSubsetOf(status));
Try It Yourself

The Try It page first checks that Set.prototype.isSubsetOf() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. Not ready yet. "test" is required but is not in done, so the answer is false.
  2. Finish the step. After done.add("test"), every required step is in done, so the same check now returns true.
  3. A Map argument. Only the keys are compared. The Map has design, code and test as keys (the true or false values do not matter), so it covers the required Set.

Browser & Runtime Support

Set.prototype.isSubsetOf() is one of the new Set methods added in ES2025. It works in current browsers and in Node.js 22 or newer, but not in older versions.

✓ Newer · ES2025

set.isSubsetOf()

Supported in Chrome 122+, Edge 122+, Firefox 127+, Safari 17+, Opera 108+ and Node.js 22+. Internet Explorer never got it.

ES2025 Standard since
Google Chrome 122+ · Desktop & Mobile
Full support
Microsoft Edge 122+ · Chromium based
Full support
Mozilla Firefox 127+ · Desktop & Mobile
Full support
Apple Safari 17+ · macOS & iOS
Full support
Opera 108+ · Chromium based
Full support
Samsung Internet 26+ · Android
Supported
Android WebView 122+ · Chromium based
Supported
Node.js 22+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
set.isSubsetOf() Recent browsers

Bottom line: Check support with typeof Set.prototype.isSubsetOf === "function". For older browsers, the same result can be made with the spread syntax and filter(), or with a loop.

Frequently Asked Questions

It checks whether every value of the Set is also in the other Set. It returns true if nothing is missing and false if at least one value is not found.
Yes. An empty Set has no value that could be missing from another Set, so isSubsetOf() returns true. A Set is also a subset of itself and of any Set with the same values.
Combine the check with a size comparison: a.isSubsetOf(b) && a.size < b.size. This means b has at least one extra value.
They ask the same question from two sides. a.isSubsetOf(b) is true when b contains all of a, and that is the same as b.isSupersetOf(a).
Use [...a].every((x) => b.has(x)). It returns true when every value of a is found in b, which is the same answer.

Next: isSupersetOf()

Learn how to check that a Set contains every value of another Set.

isSupersetOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful