JavaScript: Map Object

By Xah Lee. Date: . Last updated: .

New in JS2015.

Map is the value of the property key "Map" of the Global Object .

console.log( window["Map"] === Map ); // true

Type

Type of Map is a function.

console.log( typeof Map === "function" ); // true

Parent

Parent of Map is Function.prototype. [see Prototype and Inheritance]

console.log( Reflect.getPrototypeOf ( Map ) === Function.prototype ); // true

Purpose

Purpose of Map is:

Facts about map:

[see the Map Object Tutorial]

How Map Determines Uniqueness of Keys

The equality test used for determining whether 2 keys in a map is the same as ===, except treatment of NaN (not a number).

NaN === NaN return false, but for map object, NaN is considered same as any NaN.

// this is false
console.log(NaN === NaN); // false

// for map object, NaN is same as any NaN
const m = new Map();
m.set(NaN, "n1");
m.set(NaN, "n2");

console.log(m) // Map { NaN => 'n2' }

Constructor

Map Constructor

Properties

JavaScript Map Object

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Map

prototype