jskatas.org Continuously Learn JavaScript. Your Way.

Map: map.set()

Map.prototype.set adds a new element with key and value to a Map.

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.prototype.set adds a new element with key and value to a Map

  • simplest use case is set(key, value) and get(key)
  • the key can be a complex type too
  • calling set() again with the same key replaces the value
  • set() returns the map object, it`s chainable