--- title: Map.prototype.get() slug: Web/JavaScript/Reference/Global_Objects/Map/get tags: - ECMAScript 2015 - JavaScript - Map - Method - Prototype - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Map/get original_slug: Web/JavaScript/Reference/Global_Objects/Map/get browser-compat: javascript.builtins.Map.get ---
get() 方法返回某个 Map 对象中的一个指定元素。
myMap.get(key);
Map 对象中获取的元素的键。返回一个 Map 对象中与指定键相关联的值,如果找不到这个键则返回 undefined。
get 方法var myMap = new Map();
myMap.set("bar", "foo");
myMap.get("bar"); // 返回 "foo"
myMap.get("baz"); // 返回 undefined
| 规范 | 状态 | 备注 |
|---|---|---|
| {{SpecName('ES2015', '#sec-map.prototype.get', 'Map.prototype.get')}} | {{Spec2('ES2015')}} | Initial definition. |
| {{SpecName('ESDraft', '#sec-map.prototype.get', 'Map.prototype.get')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Map.get")}}