A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-array-keys-method/ below:

JavaScript Array keys() Method - GeeksforGeeks

JavaScript Array keys() Method

Last Updated : 11 Jul, 2025

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.

javascript
// 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 2

Example 2: In this example, we will see the use of Array.keys() method.

javascript
// 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 3

We 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:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4