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!

Map

The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.


Source: Mozilla, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.