JavaScript WeakSet Methods

Beginner
3 min read
Updated: Nov 2026
3 method guides
Method index

About This Index

This page is the JavaScript WeakSet Methods index for the tutorial track. Each row links to a full guide with syntax, three runnable examples, browser notes, and FAQs.

Learn what a WeakSet is on /js/weakset. Use this page when you need a specific method such as add(), delete(), or has().

Objects only, and no listing.

A WeakSet holds objects and nothing else. You can add, remove, and check them, but you cannot count them or loop over them.

How to Call a WeakSet Method

Create the set with new, then use a dot on it:

JavaScript
const set = new WeakSet();
const user = { name: "Ada" };

set.add(user);       // add an object, returns the set
set.has(user);       // true
set.delete(user);    // true (it was there, now removed)
set.has(user);       // false

JavaScript WeakSet Methods Table

All method guides in this JavaScript tutorial series (3 tutorials), grouped by what they do.

Add objects

1 method

Put an object into the set. A WeakSet only accepts objects, and adding the same object twice changes nothing.

MethodDescriptionTutorial
add()Add an object to a WeakSet. Returns the WeakSet, so calls can be chained.Open

Remove objects

1 method

Take one object out of the set and find out whether it was really there.

MethodDescriptionTutorial
delete()Remove an object from a WeakSet. Returns true if it was there, false if not.Open

Check membership

1 method

Ask whether an exact object is in the set. This is the only way to read a WeakSet.

MethodDescriptionTutorial
has()Check whether an object is in a WeakSet. Returns true or false and never throws.Open

WeakSet Constructor and Missing Members

These are used with new or read with a dot. The last rows list what a WeakSet does not have, so you do not look for it.

MemberWhat it gives youSince
new WeakSet()Create an empty WeakSet.ES2015
new WeakSet(iterable)Create a WeakSet and call add() for every object in the iterable, such as an array. Any item that is not an object throws a TypeError.ES2015
weakSet.sizeDoes not exist. Reading it gives undefined, because a WeakSet cannot be counted.Never
weakSet.clear()Does not exist. To start over, replace the set with a new WeakSet.Never
weakSet.forEach()Does not exist, and neither do keys(), values(), entries(), or for...of. A WeakSet cannot be looped over.Never
weakSet.add(symbol)A symbol made with Symbol() is accepted as a value. A symbol from Symbol.for() still throws a TypeError.ES2023

Frequently Asked Questions

There are only three: add(), delete(), and has(). A WeakSet has no size, no clear(), and no forEach(), because its contents cannot be counted or listed.
The WeakSet page explains what a WeakSet is, what weak means, and how it differs from a Set. This index lists every method tutorial plus the constructor and the members a WeakSet does not have, so you can jump straight to the method you need.
Create a set with new WeakSet(), then use a dot on it: set.add(obj), set.has(obj), set.delete(obj). Every method takes one object. Only add() throws a TypeError when you pass something that is not an object.
Because it holds objects weakly, the engine may clean up an object at a moment you cannot see. Anything that counts or lists the contents, like size or forEach(), would give unpredictable results, so those features were left out.
Read JavaScript WeakSet first to learn the idea, then add() to put objects in, has() to check them, and delete() to take them out. The browser support notes on each page say which versions work.

Start with add()

Learn how to put objects into a WeakSet, and why a number or string throws.

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.

14 people found this page helpful