Array.prototype.entries()

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

Syntax

entries()

Return value

A new Array iterator object.

Examples

Iterating with index and element

const a = ['a', 'b', 'c'];

for (const [index, element] of a.entries())
  console.log(index, element);

// 0 'a'
// 1 'b'
// 2 'c'

Using a for...of loop

var a = ['a', 'b', 'c'];
var iterator = a.entries();

for (let e of iterator) {
  console.log(e);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']

Specifications

Specification
ECMAScript Language Specification
# sec-array.prototype.entries

Browser compatibility

BCD tables only load in the browser

See also