JavaScript: Map Constructor

By Xah Lee. Date: .

New in JS2015.

new Map()
Create a empty map.
new Map(iterable)
Create a map from values in Iterable.
const m = new Map();

// add new item
m.set(1, "n1");
m.set(2, "n2");

console.log(m); // Map { 1 => 'n1', 2 => 'n2' }

Example of array to map:

// using nested array as literal expression for map
const m = new Map([ [3, "n3"], [4, "n4"]]);
console.log(m); // Map { 3 => 'n3', 4 => 'n4' }

Any Iterable can be used as argument.

Convert Object To/From Map

Convert Object to/from Map

JavaScript Map Object

∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Map

prototype