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
Syntax
array.entries()
Return value
An array iterator.
Examples
const fruits = ["apple", "banana"];
for (const [i, fruit] of fruits.entries()) {
console.log(i, fruit);
}
Output
0 apple 1 banana
console.log([...["a", "b"].entries()]);
Output
[ [ 0, 'a' ], [ 1, 'b' ] ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
enumerate()· Python
Related
array.keys()· Return an iterator of the array's indexes, including indexes of empty slots.array.values()· Return an iterator of the array's values, the same thing a for…of loop uses.array.forEach()· Call a function once for each element. It returns undefined, so use map() when you need a new array.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial