Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Map
  6. get()

Map.prototype.get()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Theget() method ofMap instances returns the value corresponding to the key in thisMap, orundefined 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 theMap.

Try it

const map = new Map();map.set("bar", "foo");console.log(map.get("bar"));// Expected output: "foo"console.log(map.get("baz"));// Expected output: undefined

Syntax

js
get(key)

Parameters

key

The key of the value to return from theMap object. Object keys are compared byreference, not by value.

Return value

The value associated with the specified key in theMap object. If the key can't be found,undefined is returned.

Examples

Using get()

js
const myMap = new Map();myMap.set("bar", "foo");console.log(myMap.get("bar")); // Returns "foo"console.log(myMap.get("baz")); // Returns undefined

Using get() to retrieve a reference to an object

js
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"]

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-map.prototype.get

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp