Creating a Map

suggest change

A Map is a mapping of keys to values. Map keys can be any value, not only strings and symbols. Iteration follows insertion order. An ordinary object's string keys are also insertion-ordered, except integer-index keys, which are listed first.

To create a Map, use the Map constructor:

const map = new Map();

The constructor takes an optional iterable of pairs (for example an array of two-element arrays). The first element of each pair is the key, and the second is the value. document.body in the example exists only in a browser:

const map = new Map([[new Date(), {foo: "bar"}], [document.body, "body"]]);
//                      ^key          ^value          ^key        ^value

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents