Favorites

JavaScript Map.prototype.get() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Map.prototype.get()
JavaScript Map Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

const m = new Map([['a', 1]]);
console.log(m.get('a'));
console.log(m.get('b'));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee