Javascript - Array entries() Method

The entries() method returns an Array Iterator object with key/value pairs.


The entries() method returns an Array Iterator object with key/value pairs.

For each item in the original array, the iteration object contains an array with the index as the key, and the item value as the value:

[0, "XML"][1, "Json"][2, "Database"][3, "Mango"]



Parameter Values

No parameters.


An Array Iterator object


Create an Array Iterator object, with key/value pairs for each item in the array:


var myArray = ["XML", "Json", "Database", "Mango"];
var x = myArray.entries();


The entries() method returns a sequence of values as an iterator.

An iterator provides a next() method that returns the next item in the sequence.

The next() method returns an object with two properties:

  • done, a Boolean that is true when all the elements of the iterable have been iterated over
  • value, represents the item in the collection .

Every iterable must implement the iterable protocol, meaning that the object must have a property with a Symbol.iterator key.

const arr = [11,12,13]; 
const itr = arr[Symbol.iterator]();; // { value: 11, done: false }; // { value: 12, done: false }; // { value: 13, done: false }; // { value: undefined, done: true } 

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


const breakfast = ['XMLs', 'Screens', 'Keyboards']; 
const eBreakfast = breakfast.entries(); 

console.log(; // [0, 'XMLs'] 
console.log(; // [1, 'Screens'] 
console.log(; // [2, 'Keyboards']


You can use a for-of loop to iterate over the iterator returned from the breakfast.entries() call:

for (let entry of eBreakfast) { 
// [0, 'XMLs'] 
// [1, 'Screens'] 
// [2, 'Keyboards']