JavaScript new Map()
- Vorherige Seite new Map()
- Nächste Seite clear()
- Zurück zur Oberfläche JavaScript Map Referenzhandbuch
Definition and usage
new Map()
The constructor is used to create Map objects.
Note
The Map object can only be created through new Map()
to construct.
Instance
Example 1
Through new Map()
The constructor is used to create Map objects by passing an array to create a Map object:
// 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 the 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 | The 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 | Juni 2017 | September 2016 | Juni 2016 |
Map wird in Internet Explorer nicht unterstützt.
- Vorherige Seite new Map()
- Nächste Seite clear()
- Zurück zur Oberfläche JavaScript Map Referenzhandbuch