array.values
array.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
迭代器对象。
示例
使用 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 Latest Draft (ECMA-262)The definition of 'Array.prototype.values' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | No | (Yes) | No1 | No | No | 9 |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | No | No | (Yes) | No | No | No | No |