67
JavaScript WeakMap set() method
The JavaScript WeakMap set() method is used to add or update an element to WeakMap object with the particular key-value pair. Each value must have a unique key (i.e. object).
Syntax
The set() method is represented by the following syntax:
Parameter
key – It represents the key to be added.
value – It represents the value to be added.
Return
The WeakMap object.
JavaScript WeakMap set() method example
Here, we will understand set() method through various examples.
Example 1
Let’s see an example to add elements to WeakMap object.
Output:
jQuery AngularJS Bootstrap
Example 2
Let’s see an example to add elements to WeakMap object in chainable form.
Output:
jQuery AngularJS Bootstrap
Example 3
In this example, we will determine the result when different values are added to the same object.
Output:
jQuery Bootstrap Bootstrap
Next TopicJavaScript WeakMap