在线文档教程

map.get

map.get

get() 方法用来获取一个 Map?对象中指定的元素。

语法

myMap.get(key

参数

key 想要获取的元素的键

返回值

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

示例

使用get方法

var myMap = new Map( myMap.set('bar', 'foo' myMap.get('bar' // Returns "foo". myMap.get('baz' // Returns undefined.

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Map.prototype.get' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Map.prototype.get' in that specification.Draft

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support38(Yes)13.0 (13.0)11257.1

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo support38(Yes)13.0 (13.0)No supportNo support8