entries() method returns an Array Iterator object that contains the key/value pairs for each index in the array.
entries() method does not accept any parameter.
entries() method does not change the original array.
entries() method iterates empty slots as if they had the value undefined.
The Array iterator object has a built-in method called next() that can be used to get the next value.
const myArray1 = ['a', 'b', 'c'];
const iterator = myArray1.entries();
console.log(iterator.next().value);
console.log(iterator.next().value);
console.log(iterator.next().value); returns ↴
[0, 'a']
[1, 'b']
[2, 'c']
Or we can use a for-of loop to iterate over each element in the array ↴
const myArray2 = ['a', 'b', 'c'];
for (let element of myArray2.entries())
console.log(element); returns ↴
[0, 'a']
[1, 'b']
[2, 'c']
using destructuring ↴
const myArray3 = ['a', 'b', 'c'];
for (let [key, value] of myArray3.entries())
console.log(`${key}: ${value}`); returns ↴
0: a
1: b
2: c
myArray.entries()