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

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

{{EmbedInteractiveExample("pages/js/array-entries.html")}}

구문

arr.entries()

반환 값

{{jsxref("Array")}} 반복자 인스턴스 객체.

예시

인덱스와 요소 이터레이팅

const a = ['a', 'b', 'c'];

for (const [index, element] of a.entries())
  console.log(index, element);

// 0 'a'
// 1 'b'
// 2 'c'

for…of 루프 사용

var a = ['a', 'b', 'c'];
var iterator = a.entries();

for (let e of iterator) {
  console.log(e);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']

Specifications

Specification
{{SpecName('ESDraft', '#sec-array.prototype.entries', 'Array.prototype.entries')}}

브라우저 호환성

{{Compat("javascript.builtins.Array.entries")}}

같이 보기