The Javascript array.keys() method is used to return a new array iterator which contains the keys for each index in the given input array. Syntax:
array.keys()Parameters: This method does not accept any parameters.
Return Values: It returns a new array iterator.
The below example illustrates the Array keys() method in JavaScript:
Example 1: In this example, we will see the use of Array.keys() method.
// Taking input as an array A
// containing some elements.
let A = [5, 6, 10];
// array.keys() method is called
let iterator = A.keys();
// printing index array using the iterator
for (let key of iterator) {
console.log(key);
}
Output:
0 1 2Example 2: In this example, we will see the use of Array.keys() method.
// Taking input as an array A
// containing some elements.
let A = ['gfg', 'geeks', 'cse', 'geekpro'];
// array.keys() method is called
let iterator = A.keys();
// printing index array using the iterator
for (let key of iterator) {
console.log(key);
}
Output:
0 1 2 3We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
Supported Browsers: The browsers supported by the JavaScript Array keys() method are listed below:
- Google Chrome 38.0
- Microsoft Edge 12.0
- Mozilla Firefox 28.0
- Safari 8.0
- Opera 25.0
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
