JavaScript Set Methods

Beginner
5 min read
Updated: Nov 2026
16 method guides
Method index

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().

Seven methods are new in ES2025.

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:

JavaScript
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 methods

Put values into a Set and take them out again.

MethodDescriptionTutorial
add()Put a value into a Set. A repeated value is ignored, and the Set is returned so calls can be chained.Open
delete()Remove one value. Returns true if it was there and false if not.Open
clear()Remove every value and keep the same Set object.Open

Check a value

1 method

Ask whether a value is inside a Set.

MethodDescriptionTutorial
has()Returns true if the value is in the Set. It finds NaN and compares objects by identity.Open

Loop over a Set

5 methods

Visit the values in the order they were added.

MethodDescriptionTutorial
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 methods

Build a new Set from two Sets. The original Sets never change.

MethodDescriptionTutorial
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 methods

Answer yes or no questions about two Sets.

MethodDescriptionTutorial
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

add(), clear(), delete(), entries(), forEach(), has(), keys(), values() and [Symbol.iterator]() since ES2015, plus union(), intersection(), difference(), symmetricDifference(), isSubsetOf(), isSupersetOf() and isDisjointFrom() from ES2025. It also has the size property.
The Set page explains the idea: unique values, how a Set differs from an array, and how values are compared. This index lists the method guides so you can jump straight to the one you need.
add(), delete() and clear() change the Set you call them on. The ES2025 methods such as union() and intersection() never change it: they return a new Set or a boolean.
To match Map. Code that works with a Map can then also work with a Set. In a Set, keys() is the same as values(), and entries() gives [value, value] pairs.
Start with add(), has() and delete() to learn the basics, then read forEach() and values() to loop. When you are ready, learn union() and intersection() to combine Sets. If you want the big picture first, read the Set page.

Start with add()

Open the guide for putting values into a Set: syntax, examples, and FAQs.

add() 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.

12 people found this page helpful