Practice: Working with Map Objects

Map objects are collections of key-value pairs where each key in the Map can only occur once and is unique within the Map's collection. A Map object is iterated by key-value pairs, meaning that a for...of loop returns a 2-member array of [key, value] for each iteration. Iteration occurs in insertion order, which corresponds to the order in which each key-value pair was first inserted into the map using the set() method (that is, if there was not already a key with the same value present when set() was called). Try the examples at the end of the section. These exercises do not count toward your grade. It is just for practice!

Instance properties

These properties are defined on Map.prototype and shared by all Map instances.

Map.prototype.constructor

The constructor function that created the instance object. For Map instances, the initial value is the Map constructor.

Map.prototype.size

Returns the number of key/value pairs in the Map object.

Map.prototype[@@toStringTag]

The initial value of the @@toStringTag property is the string "Map". This property is used in Object.prototype.toString().