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) The definition of 'Array.prototype.keys' in that specification. |
Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) The definition of 'Array.prototype.keys' in that specification. |
Draft |
브라우저 호환성
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | 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