Array.prototype.keys()

The keys() method returns a new Array Iterator object that contains the keys for each index in the array.

Syntax

keys()

Return value

A new Array iterator object.

Examples

Key iterator doesn't ignore holes

var arr = ['a', , 'c'];
var sparseKeys = Object.keys(arr);
var denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys);  // [0, 1, 2]

Specifications

Specification
ECMAScript Language Specification (ECMAScript)
#sec-array.prototype.keys

Browser compatibility

BCD tables only load in the browser

See also