Array indexes are useful when a value occurs twice. entries() keeps the position and the value together while the loop advances.
Worked example
console.log([...["a", "b"].entries()]);Result
[ [ 0, 'a' ], [ 1, 'b' ] ]Implementation notes
The iterator is a view over the array as it is consumed. If another part of the loop inserts or removes entries, indexes can stop referring to the records you thought you were processing.
Try it yourself
Repeat a value at the start and end. Check that both positions survive.
Open the JavaScript example →Editorial date June 21, 2026 · Published December 6, 2026