| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The get() method of Map instances returns the value corresponding to the key in this Map, or undefined if there is none. Object values are returned as the same reference that was originally stored, not as a copy, so mutations to the returned object will be reflected anywhere that reference is held, including inside the Map.
const map = new Map();
map.set("bar", "foo");
console.log(map.get("bar"));
// Expected output: "foo"
console.log(map.get("baz"));
// Expected output: undefined
get(key)
keyThe key of the value to return from the Map object. Object keys are compared by reference, not by value.
The value associated with the specified key in the Map object. If the key can't be found, undefined is returned.
const myMap = new Map();
myMap.set("bar", "foo");
console.log(myMap.get("bar")); // Returns "foo"
console.log(myMap.get("baz")); // Returns undefined
const arr = [];
const myMap = new Map();
myMap.set("bar", arr);
myMap.get("bar").push("foo");
console.log(arr); // ["foo"]
console.log(myMap.get("bar")); // ["foo"]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-map.prototype.get |
This page was last modified on Sep 22, 2025 by MDN contributors.
MapObject/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |