JavaScript new Map()
- Previous Page new Map()
- Next Page clear()
- Go Up One Level JavaScript Map Reference Manual
Course recommendation:
new Map()
Definition and usage
The constructor is used to create Map objects.
Note new Map()
Map objects can only be created through
to construct.
Instance
Example 1 new Map()
Constructor is used to create Map objects by passing an array to:
// Create a Map const fruits = new Map([ ["apples", 500], ["bananas", 300], ["oranges", 200] ]);
Example 2
Create a new Map object and use set()
Method to add elements:
// Create a Map const fruits = new Map(); // Set the value of Map fruits.set("apples", 500); fruits.set("bananas", 300); fruits.set("oranges", 200);
Syntax
new Map(iterable)Parameter
Parameter | Description |
---|---|
iterable | Optional. An iterable object containing key-value pairs. |
Return value
Type | Description |
---|---|
Object | New Map object. |
Browser support
Map is a feature of ECMAScript6 (ES6).
Starting from June 2017, all modern browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | April 2017 | June 2017 | September 2016 | June 2016 |
Map is not supported in Internet Explorer.
- Previous Page new Map()
- Next Page clear()
- Go Up One Level JavaScript Map Reference Manual