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/set/values/index.html | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/set/values/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/set/values/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/values/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/values/index.html new file mode 100644 index 0000000000..846bd7421d --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/set/values/index.html @@ -0,0 +1,70 @@ +--- +title: Set.prototype.values() +slug: Web/JavaScript/Reference/Global_Objects/Set/values +tags: + - ECMAScript 2015 + - Iterator + - JavaScript + - Method + - Prototype + - set +translation_of: Web/JavaScript/Reference/Global_Objects/Set/values +--- +
{{JSRef}}
+ +

values() 方法按照元素插入顺序返回一个具有 Set 对象每个元素值的全新 Iterator 对象。

+ +

keys() 方法是这个方法的别名(与 {{jsxref("Map")}} 对象相似);他们的行为一致,都是返回Set 对象中的元素值。

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

语法

+ +
mySet.values();
+
+ +

返回值

+ +

按照元素插入顺序返回一个包含给定的 Set 对象中每个元素值的全新 Iterator 对象。

+ +

示例

+ +

使用 values()

+ +
var mySet = new Set();
+mySet.add('foo');
+mySet.add('bar');
+mySet.add('baz');
+
+var setIter = mySet.values();
+
+console.log(setIter.next().value); // "foo"
+console.log(setIter.next().value); // "bar"
+console.log(setIter.next().value); // "baz"
+ +

规范

+ + + + + + + + + + +
规范
{{SpecName('ESDraft', '#sec-set.prototype.values', 'Set.prototype.values')}}
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.Set.values")}}

+ +

参见

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