values()
方法按照元素插入顺序返回一个具有 Set
对象每个元素值的全新 Iterator
对象。
keys()
方法是这个方法的别名(与 Map
对象相似);他们的行为一致,都是返回Set
对象中的元素值。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
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"
规范
浏览器兼容性
BCD tables only load in the browser