From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/global_objects/map/get/index.html | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/map/get/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/map/get') diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/get/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/get/index.html new file mode 100644 index 0000000000..1de9947bc4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/map/get/index.html @@ -0,0 +1,81 @@ +--- +title: Map.prototype.get() +slug: Web/JavaScript/Reference/Global_Objects/Map/get +tags: + - ECMAScript 2015 + - JavaScript + - Map + - Method + - Prototype + - 方法 +translation_of: Web/JavaScript/Reference/Global_Objects/Map/get +--- +
{{JSRef}}
+ +

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

+ +
{{EmbedInteractiveExample("pages/js/map-prototype-get.html")}}
+ + + +

语法

+ +
myMap.get(key);
+ +

参数

+ +
+
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")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf