From b9afb23d12dcae1e09f8d04c72143c5ddaa34aea Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Fri, 16 Jul 2021 16:27:00 -0400 Subject: delete conflicting/orphaned docs (zh-CN) (#1412) * delete conflicting docs (zh-CN) * and redirects * do orphaned as well * fix * remove more orphans * revert orphaned docs that can identify origin * move orphaned docs to current loc * adjust slug path * fix redirect change from rebase Co-authored-by: Irvin --- .../reference/global_objects/map/set/index.html | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/map/set/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/map/set') diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html new file mode 100644 index 0000000000..ae2ff00036 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html @@ -0,0 +1,97 @@ +--- +title: Map.prototype.set() +slug: Web/JavaScript/Reference/Global_Objects/Map/set +translation_of: Web/JavaScript/Reference/Global_Objects/Map/set +tags: + - ECMAScript 2015 + - JavaScript + - Map + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Map.set +--- +

{{JSRef}}

+ +

set() 方法为 Map 对象添加或更新一个指定了键(key)和值(value)的(新)键值对。

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

语法

+ +
myMap.set(key, value);
+ +

参数

+ +
+
key
+
要添加至相应 Map 对象的元素的键。
+
value
+
要添加至相应 Map 对象的元素的值。
+
+ +

返回值

+ +

Map 对象

+ +

示例

+ +

使用 set 方法

+ +
var myMap = new Map();
+
+// 将一个新元素添加到 Map 对象
+myMap.set("bar", "foo");
+myMap.set(1, "foobar");
+
+// 在Map对象中更新某个元素的值
+myMap.set("bar", "baz");
+
+ +

链式使用 set 方法

+ +

因为 Set() 方法返回 Map 对象本身,所以你可以像下面这样链式调用它:

+ +
// Add new elements to the map with chaining.
+myMap.set('bar', 'foo')
+     .set(1, 'foobar')
+     .set(2, 'baz');
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName('ES2015', '#sec-map.prototype.set', 'Map.prototype.set')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-map.prototype.set', 'Map.prototype.set')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.Map.set")}}

+ +

参见

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