JavaScript (ES2026) reference · Array Methods

JavaScript Array entries() Method

Return an iterator of [index, element] pairs, handy for looping with both the index and the value.

JavaScript (ES2026) Since ES2015

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.entries()

Return value

An array iterator.

Examples

Index and value in for…ofTry it yourself
const fruits = ["apple", "banana"];
for (const [i, fruit] of fruits.entries()) {
  console.log(i, fruit);
}

Output

0 apple
1 banana
Spread into an arrayTry it yourself
console.log([...["a", "b"].entries()]);

Output

[ [ 0, 'a' ], [ 1, 'b' ] ]

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?