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

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