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']

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Array.prototype.entries' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Array.prototype.entries' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support38(已实现)28未实现257.1

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(已实现)(已实现)(已实现)28未实现(已实现)8