当前位置:首页 > 手册大全 > javascript手册 > Array.prototype.values()
 

values() 方法返回一个新的 Array Iterator 对象,该对象包含数组每个索引的值

语法

arr.values()

示例

使用 for...of 循环进行迭代

let arr = ['w', 'y', 'k', 'o', 'p'];
let eArr = arr.values();
// 您的浏览器必须支持 for..of 循环
// 以及 let —— 将变量作用域限定在 for 循环中
for (let letter of eArr) {
  console.log(letter);
}

另一种迭代方式

let arr = ['w', 'y', 'k', 'o', 'p'];
let eArr = arr.values();
console.log(eArr.next().value); // w
console.log(eArr.next().value); // y
console.log(eArr.next().value); // k
console.log(eArr.next().value); // o
console.log(eArr.next().value); // p

规范

规范名称 规范状态 备注
ECMAScript 2015 (6th Edition, ECMA-262)
Array.prototype.values
Standard 首次定义
ECMAScript Latest Draft (ECMA-262)
Array.prototype.values
Draft  

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Basic support Chrome Full support 66 Edge Full support Yes Firefox Full support 60 IE No support No Opera Full support 53 Safari Full support 9 WebView Android Full support 66 Chrome Android Full support 66 Edge Mobile Full support Yes Firefox Android Full support 60 Opera Android Full support 53 Safari iOS Full support 9 Samsung Internet Android No support No nodejs Full support 10.9.0
Full support 10.9.0
Full support 6.5.0
Notes Disabled
Notes The --harmony-array-prototype-values flag is required; the --harmony flag is not sufficient in this case.
Disabled From version 6.5.0: this feature is behind the --harmony-array-prototype-values runtime flag.
No support 0.12 — 4.0.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

相关链接

公益性全栈资源网站,鸣谢默默付出的博主、工程师、架构师们。
网站内容来源技术大牛的辛勤结晶。
81For 技术网站 Copyright ©2019 备案号:津ICP备19001147号-2