The WeakSet can only store Objects Like the WeakMap, the WeakSet cannot be looped through

Code

//ES6 Maps and Sets - The WeakSet;

let obj1 = {a:1};
let obj2 = {b:2};
let set = new WeakSet([obj1, obj2, obj1]);

set.add(obj2); // add to a weakset
set.delete(obj1); // delete from weakset

console.log(set.has(obj2)) // Check if a specific object exists in a set


1
2
3
4
5
6
7
8
9
10
11
12
Last Updated: 8/13/2019, 6:55:26 PM