MDN wants to learn about developers like you:

This is a new technology, part of the ECMAScript 2015 (ES6) standard.
This technology's specification has been finalized, but check the compatibility table for usage and implementation status in various browsers.

keys() 메서드는 배열의 각 인덱스에 대한 key들을 가지는 새로운 Array Iterator 객체를 반환합니다.




기본 사용법

var arr = ["a", "b", "c"];
var iterator = arr.keys();

console.log(; // { value: 0, done: false }
console.log(; // { value: 1, done: false }
console.log(; // { value: 2, done: false }
console.log(; // { value: undefined, done: true }

빈 요소들(holes)을 무시하지 않는 key 반복자

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)
The definition of 'Array.prototype.keys' in that specification.
Standard Initial definition.

브라우저 호환성

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38 28 (28) Not supported 25 7.1
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported Not supported 28.0 (28) Not supported Not supported 8.0

같이 보기

문서 태그 및 공헌자

 이 페이지의 공헌자: preco21
 최종 변경: preco21,