JavaScript: Map Object
New in JS2015.
Map
is the value of the property key "Map"
of the Global Object
.
console.log(globalThis["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:
- To create instance of “map” object. Instance of map object is a collection of key/value pairs as a lookup table data structure. This is different from the generic data object. The map object instance is designed specifically as a lookup table data structure.
- Used as a namespace to hold general purpose methods for working with “map” instances.
- Holds the property key
"prototype"
. The value ofMap.prototype
is the parent object of all “map” instances.
Facts about map:
- Map instances are collections of key/value pairs.
- Key can be any type. [see Value Types]
- Value can be any type.
- Keys are always distinct.
- The insertion order of entries are maintained.
[see the Map Object Tutorial]