`keys()` 方法返回一个包含数组中每个索引键的`Array Iterator`对象。

## 语法

    arr.keys()

### 返回值

一个新的 `Array` 迭代器对象。

## 示例

### 索引迭代器会包含那些没有对应元素的索引

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

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript 2015 (6th Edition, ECMA-262) Array.prototype.keys | Standard | Initial definition.
ECMAScript Latest Draft (ECMA-262) Array.prototype.keys | Draft |

## 浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

| Desktop | Mobile | Server
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js
`keys` | Chrome Full support 38 | Edge Full support 12 | Firefox Full support 28 | IE No support No | Opera Full support 25 | Safari Full support 8 | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 28 | Opera Android Full support Yes | Safari iOS Full support 8 | Samsung Internet Android Full support Yes | nodejs Full support 0.12

### Legend

Full support
  Full support
No support
  No support

## 相关链接

- `Array.prototype.values()`
- `Array.prototype.entries()`
- Iteration protocols