JavaScript new Map()
Examples
Creating a Map object by passing an array to thenew Map() constructor:
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
Try it Yourself »const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
Creating a new Map object and add elements with theset() method:
// 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 »const fruits = new Map();
// Set Map Values
fruits.set("apples", 500);
fruits.set("bananas", 300);
fruits.set("oranges", 200);
Description
Thenew Map() constructor creates a Map object.
Note
A Map object can only be constructed withnew Map()
Syntax
new Map(iterable)
Parameters
| Parameter | Description |
| iterable | Optional. An iterable object with key-value pairs. |
Return Value
| Type | Description |
| Object | A new Map object. |
Browser Support
Map is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers sinceJune 2017:
| Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |

