Javascript array keys() method returns the new Array Iterator object that contains the keys for each index in an array. The array keys() method does not change the original array.

Javascript Array Keys Example

The syntax for the Javascript Array keys() method is the following.

arr.keys()

Let us take a simple example.

// app.js

let arr = ['a', 'b', 'c'];
let iteratorObj = arr.keys();

console.log(iteratorObj);

So, it has given us iteratorObj. We can get the values by iterating for…of() loop.

// app.js

let arr = ['a', 'b', 'c'];
let iterator = arr.keys();

console.log(iterator);

for (let key of iterator) {
  console.log(key);
}

#javascript #javascript array keys #js

Javascript Array Keys Example | Array Keys In Javascript
1.65 GEEK