Array.prototype.entries()

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

Try it

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

const array = ["a", "b", "c"];
const arrayEntries = array.entries();

for (let element of arrayEntries) {
  console.log(element);
}

// [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