--- 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 ---
keys()
메서드는 배열의 각 인덱스를 키 값으로 가지는 새로운 Array Iterator
객체를 반환합니다.
{{EmbedInteractiveExample("pages/js/array-keys.html")}}
arr.keys()
새로운 {{jsxref("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 |
---|---|---|
{{SpecName('ES6', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ES6')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Array.keys")}}