JavaScript Array.prototype.keys() Method
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
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.
Desktop





Tablets & Mobile





