JavaScript WeakSet Object
A WeakSet is a collection of objects held weakly, so they can still be garbage-collected. It is used to mark objects, for example to remember which ones have already been processed.
Description
A WeakSet stores objects (or non-registered symbols), each at most once, and holds them weakly: being in the set doesn't stop an object from being garbage-collected. That makes it useful for tagging objects, such as tracking which elements have been initialized, without keeping them alive.
Like WeakMap, it can't be iterated and has no size; it only has add(), has() and delete().
Only objects and non-registered symbols can be added; adding a primitive throws a TypeError. A common use is preventing an operation from running twice on the same object, such as attaching listeners to an element, or detecting circular references while walking an object graph. If you need to list the members or know how many there are, use a regular Set.
Creating
new WeakSet()
new WeakSet(iterable)Example
Browser Support
The following information will show you the current browser support for the WeakSet object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





