keys() – Iterator containing indices
array.keys();
array
is an array of elementskeys
is the array method name
keys()
method returns Array Iterator object with keys for each index in the array
Examples
1. get keys iterator object for the fruits
array, and print the first two values
let fruits = ['apple', 'banana', 'cherry', 'fig'];
let keys = fruits.keys();
console.log(keys.next().value);
console.log(keys.next().value);