Map() constructor - JavaScript | MDN

Syntax

js

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

js

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

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-map-constructor

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.