Favorites

JavaScript Array.prototype.keys() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.keys()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The keys() method returns an iterator over the indexes of an array.

Description

The keys() method returns an iterator of the array's indexes, 0, 1, 2 and so on. Unlike Object.keys(), it includes the indexes of empty slots in sparse arrays.

It's mostly used to create ranges, as in [...Array(5).keys()].

Like the other array iterators, it can be combined with iterator helpers or spread into an array. Remember that the iterator produces numbers, while for...in over an array gives index strings. To get indexes and values together, entries() is usually more useful.

Syntax

array.keys()

Return Value

A new array iterator that yields each index.

Example

console.log([...['a', 'b', 'c'].keys()]);
console.log([...Array(5).keys()]);

Browser Support

The following information will show you the current browser support for the Array.prototype.keys() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee