Array.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 May 2018.

values() 方法會回傳一個包含陣列中的每一個索引之對應值(value)的新 Array Iterator 物件。

js
var a = ["w", "y", "k", "o", "p"];
var iterator = a.values();

console.log(iterator.next().value); // w
console.log(iterator.next().value); // y
console.log(iterator.next().value); // k
console.log(iterator.next().value); // o
console.log(iterator.next().value); // p

語法

js
arr.values()

回傳值

一個新的 Array 迭代器(iterator)物件。

範例

使用 for...of 迴圈進行迭代

js
var arr = ["w", "y", "k", "o", "p"];
var iterator = arr.values();

for (let letter of iterator) {
  console.log(letter);
}

規範

Specification
ECMAScript® 2025 Language Specification
# sec-array.prototype.values

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
values

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

參見