values()
方法會回傳一個包含陣列中的每一個索引之對應值(values)的新 Array Iterator
物件。
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
語法
arr.values()
回傳值
一個新的 Array
迭代器(iterator)物件。
範例
使用
for...of
迴圈進行迭代
var arr = ['w', 'y', 'k', 'o', 'p'];
var iterator = arr.values();
for (let letter of iterator) {
console.log(letter);
}
規範
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.values' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Array.prototype.values' in that specification. |
Living Standard |
瀏覽器相容性
BCD tables only load in the browser
The compatibility table in 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.