Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

The WeakSet object lets you store weakly held objects in a collection.


 new WeakSet([iterable]);


If an iterable object is passed, all of its elements will be added to the new WeakSet. null is treated as undefined.


Using the WeakSet object

var ws = new WeakSet();
var window = {};
var foo = {};


ws.has(window); // true
ws.has(foo);    // false, foo has not been added to the set

ws.delete(window); // removes window from the set
ws.has(window);    // false, window has been removed


WeakSet objects are collections of objects. An object in the WeakSet may occur only once; it is unique in the WeakSet's collection.

The main differences to the Set object are:

  • In contrast to Sets, WeakSets are collections of objects only and not of arbitrary values of any type.
  • The WeakSet is weak: References to objects in the collection are held weakly. If there is no other reference to an object stored in the WeakSet, they can be garbage collected. That also means that there is no list of current objects stored in the collection. WeakSets are not enumerable.


The value of the length property is 0.
Represents the prototype for the Set constructor. Allows the addition of properties to all WeakSet objects.

WeakSet instances

All WeakSet instances inherit from WeakSet.prototype.


Returns the function that created an instance's prototype. This is the WeakSet function by default.


Appends a new object with the given value to the WeakSet object.
Removes the element associated to the value. WeakSet.prototype.has(value) will return false afterwards.
Returns a boolean asserting whether an element is present with the given value in the WeakSet object or not.
Removes all elements from the WeakSet object.


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'WeakSet' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'WeakSet' in that specification.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support361234 No239
new WeakSet(iterable)381234 No259
new WeakSet(null) Yes1237 No ?9
add36 Yes34 No239
clear36 — 43 No34 — 46 No25 — 30 No
delete36 Yes34 No239
has36 Yes34 No239
prototype36 Yes34 No239
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support36361234239 Yes
new WeakSet(iterable)38381234259 Yes
new WeakSet(null) Yes Yes1237 ?9 Yes
add3636 Yes34239 Yes
clear36 — 4336 — 43 No34 — 4625 — 30 No Yes
delete3636 Yes34239 Yes
has3636 Yes34239 Yes
prototype3636 Yes34239 Yes

See also

Schlagwörter des Dokuments und Mitwirkende

Zuletzt aktualisiert von: JonathanPool,