JavaScript Map.prototype.set() Method
The set() method adds or updates an entry in a Map and returns the Map, so calls can be chained.
Description
The set() method adds an entry or updates the value of an existing key. New keys are added at the end of the iteration order; updating a key keeps its position. Because it returns the map, you can chain calls.
Unlike object properties, map keys keep their type, so the number 1 and the string '1' are different keys. Using objects or DOM elements as keys is a common way to attach data to them, although a WeakMap is better when the keys might be removed, so the data doesn't keep them in memory.
Keys are compared with the SameValueZero algorithm: primitives by value, NaN as equal to itself, and objects only when they're the same object.
Syntax
map.set(key, value)Parameters
- keyThe key, of any type.
- valueThe value to store.
Return Value
The same Map, so calls can be chained.
Example
Browser Support
The following information will show you the current browser support for the Map.prototype.set() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





