JavaScript (ES2026) reference · Array Methods

JavaScript Array keys() Method

Return an iterator of the array's indexes, including indexes of empty slots.

JavaScript (ES2026) Since ES2015

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.keys()

Return value

An array iterator.

Examples

All indexesTry it yourself
console.log([..."abc".split("").keys()]);

Output

[ 0, 1, 2 ]
keys() includes holes; Object.keys() doesn'tTry it yourself
const sparse = ["a", , "c"];
console.log([...sparse.keys()], Object.keys(sparse));

Output

[ 0, 1, 2 ] [ '0', '2' ]

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?