The following four data structures are new in ECMAScript 6: Map, WeakMap, Set and WeakSet.

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

WeakSets have only three methods, all of them work the same as the Set methods.

  • WeakSet.prototype.add(value)
  • WeakSet.prototype.has(value)
  • WeakSet.prototype.delete(value)

WeakSet collection can‘t be iterated and we cannot determine its size.

Examples

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

ws.add(window);
ws.add(obj);

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