JavaScript Map set()
Map.set()
You can add elements to a Map with the set() method:
Example
// Create a Map
const fruits = new Map();
// Set Map Values
fruits.set("apples", 500);
fruits.set("bananas", 300);
fruits.set("oranges", 200);
Try it Yourself »
The set() method can also be used to change existing Map values:
Description
The set() method adds an element to a map.
The set() method updates an element in a map.
Syntax
map.set(key, value)
Parameters
| Parameter | Description | 
| key | Required. The element key.  | 
  
| value | Required. The element value.  | 
  
Return Value
| Type | Description | 
| Map | The map object. | 
Browser Support
map.set() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51  | 
  Edge 15  | 
  Firefox 54  | 
  Safari 10  | 
  Opera 38  | 
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |