Creating a Map
suggest changeA 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents