A Map is a collection of key-value entries that allows lookup of values by key. A Map is created by invoking new Map with an array of key-value pair arrays. Maps expose .size for the number of entries, while arrays use .length because element order matters; Map entries are unordered. Methods .get and .set allow retrieving and assigning values. .has checks for key existence. There can be at most one entry per key. Objects can be used as keys, but key comparison follows strict identity semantics (like ===). Arrays are compact but less descriptive for representing pairs.
A Map is a collection of entries. Each entry consists of a key and a value. We can look up a value via its key. That is similar to how dictionaries work - e.g. English-Spanish dictionaries: Given a word in English, you can look up a word in Spanish. That's why this data structure is often called dictionary. Creating Maps # We created a Map by invoking the class Map.
Using an array has the upside of being more compact and the downside of being less descriptive. Maps have a .size - the number of their entries: Note that an array has a .length because it is linear: The order of its elements matters. For a Map, on the other hand, the order of its entries does not matter. That's why it has a .size.
Collection
[
|
...
]