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 );

Type

Type of Map is a function.

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

Parent

Parent of Map is Function.prototype.

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

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

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Map

prototype