---
title: Array.prototype.keys()
slug: Web/JavaScript/Reference/Global_Objects/Array/keys
tags:
  - Array
  - ECMAScript 2015
  - Iterator
  - JavaScript
  - Method
  - Prototype
  - Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Array/keys
---
<div>{{JSRef}}</div>

<p><code><strong>keys()</strong></code> 메서드는 배열의 각 인덱스를 키 값으로 가지는 새로운 <code><strong>Array Iterator</strong></code> 객체를 반환합니다.</p>

<p>{{EmbedInteractiveExample("pages/js/array-keys.html")}}</p>

<h2 id="구문">구문</h2>

<pre class="syntaxbox"><code><var>arr</var>.keys()</code></pre>

<h3 id="반환_값">반환 값</h3>

<p>새로운 {{jsxref("Array")}} 반복기 객체.</p>

<h2 id="예제">예제</h2>

<h3 id="키_반복기는_빈_인덱스를_무시하지_않음">키 반복기는 빈 인덱스를 무시하지 않음</h3>

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

<h2 id="명세">명세</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-array.prototype.keys', 'Array.prototype.keys')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-array.prototype.keys', 'Array.prototype.keys')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="브라우저_호환성">브라우저 호환성</h2>

<p>{{Compat("javascript.builtins.Array.keys")}}</p>

<h2 id="같이_보기">같이 보기</h2>

<ul>
 <li>{{jsxref("Array.prototype.values()")}}</li>
 <li>{{jsxref("Array.prototype.entries()")}}</li>
</ul>