Map.prototype.get()

get() 方法返回某个 Map 对象中的一个指定元素。

语法

myMap.get(key);

参数

key
必须参数,也是它唯一的参数,要从目标 Map 对象中获取的元素的键。

返回值

返回一个 Map 对象中与指定键相关联的值,如果找不到这个键则返回 undefined

示例

使用 get 方法

var myMap = new Map();
myMap.set("bar", "foo");

myMap.get("bar");  // 返回 "foo"
myMap.get("baz");  // 返回 undefined

规范

规范 状态 备注
ECMAScript 2015 (6th Edition, ECMA-262)
Map.prototype.get
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
Map.prototype.get
Draft  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
getChrome Full support 38Edge Full support 12Firefox Full support 13IE Full support 11Opera Full support 25Safari Full support 8WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 14Opera Android Full support 25Safari iOS Full support 8Samsung Internet Android Full support 3.0nodejs Full support Yes

Legend

Full support  
Full support

参见