array.entries
array.entries
entries()
方法返回一个新的Array Iterator
对象,该对象包含数组中每个索引的键/值对。
var a = ['a', 'b', 'c'];
var iterator = a.entries(
console.log(iterator.next().value // [0, 'a']
console.log(iterator.next().value // [1, 'b']
console.log(iterator.next().value // [2, 'c']
语法
a.entries()
返回值
一个新的Array
迭代器对象。
示例
使用for…of循环
var a = ['a', 'b', 'c'];
var iterator = a.entries(
for (let e of iterator) {
console.log(e
}
// [0, 'a']
// [1, 'b']
// [2, 'c']
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Array.prototype.entries' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Array.prototype.entries' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | 38 | (已实现) | 28 | 未实现 | 25 | 7.1 |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (已实现) | (已实现) | (已实现) | 28 | 未实现 | (已实现) | 8 |