Skip to content
Related Articles

Related Articles

JavaScript WeakSet Complete Reference

Improve Article
Save Article
  • Last Updated : 23 Nov, 2022
Improve Article
Save Article

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() MethodThe 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() MethodThe weakSet.delete() is an inbuilt function in JavaScript that is used to delete a specific element from a weakSet object.
JavaScript weakSet.has() MethodThe 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
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!