--- title: Array.prototype.entries() slug: Web/JavaScript/Reference/Global_Objects/Array/entries translation_of: Web/JavaScript/Reference/Global_Objects/Array/entries ---
{{JSRef}}

Phương thức entries() trả về một mảng đối tượng Array Iterator chứa cặp key/value cho mỗi chỉ mục trong mảng.

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

Syntax

array.entries()

Return value

Một {{jsxref("Array")}} đối tượng iterator.

Examples

Iterating with index and element

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

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

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

Using a for…of loop

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')}}

Browser compatibility

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

See also