JavaScript Map.prototype.get() Method
The get() method returns the value stored for a key in a Map, or undefined.
Description
The get() method returns the value associated with a key, or undefined if the key isn't present. Object keys must be the same object, not just an equal-looking one. Since a stored value could itself be undefined, use has() to check for the key.
To provide a default for missing keys, combine it with ??: map.get(key) ?? 0. A common pattern is counting occurrences: counts.set(word, (counts.get(word) ?? 0) + 1).
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.get(key)Parameters
- keyThe key to look up.
Return Value
The value for the key, or undefined if there is none.
Example
Browser Support
The following information will show you the current browser support for the Map.prototype.get() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





