JavaScript new Map()
- Previous page new Map()
- Next page clear()
- Go up one level JavaScript Map Referentie Handleiding
Definition and usage
new Map()
The constructor is used to create Map objects.
Note
Map objects 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 the Map object:
// Create a Map const fruits = new Map([ ["apples", 500], ["bananas", 300], ]
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 | 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 |
2016 May | 2017 April | 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 Referentie Handleiding