← TechnologyThe essentials of

Map: when the identifier must result in a value

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 10:06. This is not editorial approval.

In a few sentences

In brief

Map stores key-value pairs and remembers the order of addition. set() and get() work with the collection, not with arbitrary properties on the object.

Useful to know

Map is suitable for a table of keys to values, for example, a category code to its name. The key is unique in the collection; calling set() again with the same key changes the associated value. The order of initial addition is preserved when iteration. [1]

Example: const names = new Map([['tech', 'Technology']]); names.set('food', 'Food'); names.get('tech') returns 'Technology'. For availability use names.has('food'), and for the number of pairs - names.size.

Do not record names.food = 'Food', if you expect this to become a Map entry. This creates a simple object property and get('food') does not work with it as an item in the collection. [1]

Keys can also be objects. Then keep the same reference if you want to extract the value. A new object with the same visible properties is not automatically the same key. For a catalog of persistent identifiers, the text or number key is often easier to track.

Sources

For further detail and to check the information:

  1. [1] MDN — Map ↗