The map.set() method is used to add key-value pairs to a Map object. It can also be used to update the value of an existing key. Each value must have a unique key so that they get mapped correctly.
Parameters: This method accepts two parameters as mentioned above and described below:
- Key: This is the key of the item that has to be added or updated in the Map.
- Value: This is the value of the item that has to be added or updated in the Map.
The examples below illustrate the set() method:
Example 2: Using set() with chaining
Rohan Sohan Trojan