values() 方法返回一个 Iterator 对象,该对象按照原Set 对象元素的插入顺序返回其所有元素。
keys() 方法是这个方法的别名 (与 Map 对象相似); 它的行为与 value 方法完全一致,返回 Set 对象的元素。
语法
mySet.values();
返回值
将返回一个新生成的可迭代对象,以插入 Set 对象的顺序返回其包含的每个元素的值。
示例
使用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"
规范
| 规范 | 状态 | 注释 |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) Set.prototype.values |
Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) Set.prototype.values |
Draft |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 38 | 24 (24) | 未实现 | 25 | 7.1 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 未实现 | 38 | 24.0 (24) | 未实现 | 未实现 | 8 |