Map.prototype.get()

Returns the value associated with a key in a Map.

Since ES2015 (ES6) Spec ↗

Syntax

map.get(key)

Returns

any — The value for `key`, or `undefined` if the key is absent.

Examples

const m = new Map([["x", 10]]);
console.log(m.get("x"));
console.log(m.get("missing"));
Output
10
undefined
const m = new Map();
m.set(NaN, "not a number");
console.log(m.get(NaN));
Output
not a number

Notes

- Returns `undefined` for missing keys; use `has()` to distinguish a stored `undefined` from absence. - Key lookup uses SameValueZero equality.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 13
safari 8
edge 12
node 0.12

See also