Set.prototype.values()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
values()
方法回傳一個 Iterator
物件,包含著 Set
物件中所有元素,由插入順序排序。
keys()
是這個方法的替身(為了與 Map
物件保持相似性);他運行的完全一模一樣,回傳 Set
中元素的 values。
嘗試一下
const set1 = new Set();
set1.add(42);
set1.add("forty two");
const iterator1 = set1.values();
console.log(iterator1.next().value);
// Expected output: 42
console.log(iterator1.next().value);
// Expected output: "forty two"
語法
js
mySet.values();
回傳值
一個 Iterator
物件,包含著 Set
物件中所有元素,由插入順序排序。
範例
使用 values()
js
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"
規範
Specification |
---|
ECMAScript® 2025 Language Specification # sec-set.prototype.values |
瀏覽器相容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
values |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.