JavaScript Array keys() method
returns an Array Iterator object that contains the keys for each index in the array

keys() method returns an Array Iterator object that contains the keys for each index in the array.

keys() method does not accept any parameter.

keys() method does not change the original array.

keys() method does not skip over empty slots, it will hold the key for empty slots in the array.

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.keys();

console.log(iterator.next().value);

console.log(iterator.next().value);

console.log(iterator.next().value); returns ↴

0

1

2

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.keys())

console.log(element); returns ↴

0

1

2

syntax description
returns an Array Iterator object that contains the key for each index in myAarray
myArray.keys()