JavaScript .entries()
Published Aug 6, 2025
Contribute to Docs
The entries() method returns a new array iterator object that contains key/value pairs for each index in the array. This is useful when both the index and value of array elements are needed during iteration.
Syntax
array.entries()
Parameters:
The entries() method does not take any parameters.
Return value:
A new Array Iterator object containing [index, value] pairs
Example
In this example the .entries() method is used to iterate over an array of cat names, accessing both the index and value in each loop:
const cats = ['Peche', 'Moana', 'Pintassilga'];const iterator = cats.entries();for (let [index, name] of iterator) {console.log(`Cat #${index}: ${name}`);}
The output of this code is:
Cat #0: PecheCat #1: MoanaCat #2: Pintassilga
Codebyte Example
In this example the loop prints each index and corresponding fruit name by iterating through the key/value pairs returned by .entries():
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.