JavaScript WeakSet Complete Reference
WeakSet in JavaScript is used to store a collection of objects. It adapts the same properties as that of a set i.e. does not store duplicates. The major difference between WeakSet and a set is that a WeakSet is a collection of objects and not values of some particular type.
Syntax:
weakSet.function();
Example: In thi example we will use the JavaScript weakSet() method.
Javascript
<script> // Constructing a weakSet() object const A = new WeakSet(); // Constructing new objects const object1 = {}; // Adding the new object to the weakSet A.add(object1); // Checking whether the new object is present // in the weakSet or not console.log(A.has(object1));</script> |
Output:
true
The complete list of JavaScript WeakSet are listed below:
Method:
JavaScript WeakSet Method | Description |
|---|---|
| JavaScript weakSet.add() Method | The weakSet.add() is an inbuilt function in JavaScript that is used to add an object at the end of an object WeakSet. |
| JavaScript weakSet.delete() Method | The weakSet.delete() is an inbuilt function in JavaScript that is used to delete a specific element from a weakSet object. |
| JavaScript weakSet.has() Method | The weakSet.has() is an inbuilt function in JavaScript that is used to return a boolean value indicating whether an object is present in a weakSet or not. that |






Please Login to comment...