JavaScript Set Methods

About This Index
This page is the JavaScript Set Methods index. A Set has fifteen methods plus the special [Symbol.iterator]() method. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what a Set is on /js/set. Use this page when you need a specific method such as add() or union().
The methods union(), intersection(), difference(), symmetricDifference(), isSubsetOf(), isSupersetOf() and isDisjointFrom() work in current browsers and in Node.js 22 or newer. Check typeof Set.prototype.union === "function" before you use them in older environments.
How to Call a Set Method
Create a Set, then call the methods on it:
const a = new Set([1, 2, 3]);
const b = new Set([3, 4]);
a.add(4); // put a value in
console.log(a.has(4)); // true
a.delete(1); // remove one value
a.forEach((v) => console.log(v)); // 2, 3, 4
console.log(a.union(b).size); // 3 (ES2025)
console.log(a.isSupersetOf(b)); // true (ES2025) JavaScript Set Methods Table
All method guides in this JavaScript tutorial series (16 tutorials), grouped by what they do.
Add and remove values
3 methodsPut values into a Set and take them out again.
Check a value
1 methodAsk whether a value is inside a Set.
Loop over a Set
5 methodsVisit the values in the order they were added.
| Method | Description | Tutorial |
|---|---|---|
forEach() | Run a function for every value, with the value, a key that equals the value, and the Set. | Open |
values() | An iterator of every value. Convert it with Array.from() or the spread syntax. | Open |
keys() | The same iterator as values(). It exists so Sets and Maps can share code. | Open |
entries() | An iterator of [value, value] pairs, the same shape as Map entries. | Open |
[Symbol.iterator]() | The special method behind for...of, spread and destructuring. It is the same function as values(). | Open |
Combine and compare Sets (ES2025)
4 methodsBuild a new Set from two Sets. The original Sets never change.
| Method | Description | Tutorial |
|---|---|---|
union() | Every value from both Sets, with no duplicates. | Open |
intersection() | Only the values that are in both Sets. | Open |
difference() | The values that are in the first Set but not in the second one. | Open |
symmetricDifference() | The values that are in only one of the two Sets. | Open |
Check how two Sets relate (ES2025)
3 methodsAnswer yes or no questions about two Sets.
| Method | Description | Tutorial |
|---|---|---|
isSubsetOf() | True if every value of the Set is also in the other Set. | Open |
isSupersetOf() | True if the Set contains every value of the other Set. | Open |
isDisjointFrom() | True if the two Sets have no value in common. | Open |
Frequently Asked Questions
Start with add()
Open the guide for putting values into a Set: syntax, examples, and FAQs.
12 people found this page helpful
