W3cubDocs

/JavaScript

Map() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

The Map() constructor creates Map objects.

Syntax

new Map()
new Map(iterable)

Note: Map() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

iterable Optional

If an iterable object (such as an array) is passed, all of its elements will be added to the new Map. Each element must be an object with two properties: 0 and 1, which correspond to the key and value (for example, [[1, "one"],[2, "two"]]). If you don't specify this parameter, or its value is null or undefined, the new Map is empty.

Examples

>

Creating a new Map

const myMap = new Map([
  [1, "one"],
  [2, "two"],
  [3, "three"],
]);

Specifications

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS Bun Deno Node.js
Map 38 12 13 25 8 38 14 25 8 3.0 38 8 1.0.0 1.0 0.12.0
iterable_allowed 38 12 13 25 9 38 14 25 9 3.0 38 9 1.0.0 1.0 0.12.0
null_allowed 38 12 37 25 9 38 37 25 9 3.0 38 9 1.0.0 1.0 0.12.0

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/Map