JS: Literal Expression for Map

By Xah Lee. Date: .

Literal Expression for Map

There's no literal expression for map. But you can pass in a literal expression of array of array, like this:

new Map([ [k1, v1], [k2, v2], etc])

const xx = new Map([[3, "n3"], [4, "n4"]]);

console.log(xx);
// Map { 3 => "n3", 4 => "n4" }

Note: the map constructor (new Map()) does not accept a object datatype.

[see Map Constructor]

[see Convert Object to/from Map πŸš€]

JavaScript, Map Object