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
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
get Chrome Full support 38 Edge Full support 12 Firefox Full support 13 IE Full support 11 Opera Full support 25 Safari Full support 8 WebView Android Full support 38 Chrome Android Full support 38 Firefox Android Full support 14 Opera Android Full support 25 Safari iOS Full support 8 Samsung Internet Android Full support 3.0 nodejs Full support Yes

Legend

Full support  
Full support

参见