JavaScript weakSet add() Method Last Updated : 07 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Values: It returns the newly added weakset object. Below are examples of weakSet.add() method: Example 1: This is a basic example of weakset.add() method in javascript. javascript function gfg() { const weakset = new WeakSet(); const object1 = {}; weakset.add(object1); console.log(weakset.has(object1)); } gfg(); OutputtrueExample 2: Here the output is true because the newly created objects have been set to the end of the weakSet() object. javascript // Constructing a weakset object const weakset = new WeakSet(); // Constructing a new object object1 const object1 = {}; const object2 = {}; const object3 = {}; const object4 = {}; // Adding the object1 at the end of the weakset object. weakset.add(object1); weakset.add(object2); weakset.add(object3); weakset.add(object4); // Printing either object has been added or not console.log(weakset.has(object1)); console.log(weakset.has(object2)); console.log(weakset.has(object3)); console.log(weakset.has(object4)); Outputtrue true true trueExample 3: Here the output is false because the newly created objects have not been set to the end of the weakSet() object. javascript // Constructing a weakset object const weakset = new WeakSet(); // Constructing a new object object1 const object1 = {}; const object2 = {}; const object3 = {}; const object4 = {}; // Printing either object has been added or not console.log(weakset.has(object1)); console.log(weakset.has(object2)); console.log(weakset.has(object3)); console.log(weakset.has(object4)); Outputfalse false false falseSupported Browsers:Google Chrome 36 and aboveFirefox 34 and aboveApple Safari 9 and aboveOpera 23 and aboveEdge 12 and aboveWe have a complete list of Javascript WeakSet methods, to check those please go through Javascript WeakSet Complete reference article. Comment More infoAdvertise with us Next Article JavaScript weakSet delete() Method S ShivamKD Follow Improve Article Tags : JavaScript Web Technologies JavaScript-WeakSet JavaScript-Methods 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