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
console.log([..."abc".split("").keys()]);
Output
[ 0, 1, 2 ]
const sparse = ["a", , "c"];
console.log([...sparse.keys()], Object.keys(sparse));
Output
[ 0, 1, 2 ] [ '0', '2' ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
array.entries()· Return an iterator of [index, element] pairs, handy for looping with both the index and the value.array.values()· Return an iterator of the array's values, the same thing a for…of loop uses.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial