80
JavaScript Map set() method
The JavaScript map set() method is used to add or updates an element to map object with the particular key-value pair. Each value must have a unique key.
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 Map object.
JavaScript Map set() method example
Here, we will understand set() method through various examples.
Example 1
Let’s see an example to add key and value pair of elements to map object.
Output:
jQuery AngularJS Bootstrap
Example 2
In this example, we will determine the result when same key is added with different values.
Output:
AngularJS undefined Bootstrap
Next TopicJavaScript Map