JavaScript WeakSet() Constructor Last Updated : 22 May, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript WeakSet Constructor is used to create a weakset that is similar to the set as it does not contain duplicate objects. It is different from the set as it stores a collection of weakly held objects instead of an object of a particular type. We can only create a WeakSet with the new keyword otherwise a TypeError will be thrown Syntax: new WeakSet() new WeakSet(iter) Parameter: It has one optional parameter. iter: It is an iterable object whose elements will be assigned to new WeakSet. If null is given it will be treated as undefined. Return Type: A WeakSet object Example 1: In this example, we will create a WeakSet object and add elements to it. JavaScript let x = new WeakSet(); let y = new WeakSet(null); x.add({}); x.add({}); console.log(x); console.log(y); Output: WeakSet {{…}, {…}} WeakSet {} Example 2: In this example, we will add objects with values in WeakSet and check if the element is inserted with inbuilt methods. JavaScript let looseSet = new WeakSet(); let Rahul = {name: "Rahul"}; let Vijay = {name: "Vijay"} let Ram = {name: "Ram"} looseSet.add(Rahul); looseSet.add(Vijay); console.log(looseSet.has(Rahul)); // true console.log(looseSet.has(Ram)); // false Output: true false Supported Browsers: Google ChromeFirefoxInternet ExplorerOpera Safari We have a complete list of Javascript weakSet methods, to check those please go through this JavaScript WeakSet Complete Reference article. Comment More infoAdvertise with us Next Article JavaScript WeakSet constructor Property S shobhit_sharma Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript WeakSet() Constructor JavaScript WeakSet Constructor is used to create a weakset that is similar to the set as it does not contain duplicate objects. It is different from the set as it stores a collection of weakly held objects instead of an object of a particular type. We can only create a WeakSet with the new keyword o 2 min read JavaScript WeakSet constructor Property JavaScript WeakSet constructor property is used to return the WeakSet constructor function for the object. The function returned by this property is just the reference, not the actual WeakSet. It is an object property of JavaScript and can be used with Strings, Numbers, etc. Syntax: weakset.construc 1 min read JavaScript weakSet add() Method Javascript weakSet.add() is used to add an object at the end of the object WeakSet. The WeakSet object lets you store weakly held objects in a collection. Syntax: weakSet.add(A);Parameters: This method accepts a single parameter value. value: This value will be added to the weakset object. Return Va 2 min read JavaScript weakSet delete() Method JavaScript weakSet.delete() method is used to delete a specific element from a weakSet object. The WeakSet object lets you store weakly held objects in a collection. Syntax: weakSet.delete(value); Parameters: This method accepts a single parameter value. value: This value will be deleted from the we 2 min read JavaScript weakSet has() Method JavaScript weakSet.has() method is used to return a boolean value indicating whether an object is present in a weakSet or not. The WeakSet object lets you store weakly held objects in a collection. Syntax: weakSet.has(value); Parameters: This method accepts a single parameter value. value: This valu 2 min read Like