jskatas.org Continuously Learn JavaScript. Your Way.

Map: Basics

A Map holds key-value pairs, the key can even be a complex value.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Map is a key/value map

  • Map is a global constructor function
  • provides new Map().set() to add key+value pair, get() to read it by key
  • has() tells if map has the given key
  • delete() deletes the element given by the key AND map.size reports the number of items
  • keys() and values() return iterables of the keys and values
  • a map can be iterated over using for-of
  • a map is iterable
  • complex types can be keys


MDN page about Map.
The chapter in the specification, with all details about Map.