--- title: Array.prototype.entries() short-title: entries() slug: Web/JavaScript/Reference/Global_Objects/Array/entries page-type: javascript-instance-method browser-compat: javascript.builtins.Array.entries sidebar: jsref --- The **`entries()`** method of {{jsxref("Array")}} instances returns a new _[array iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator)_ object that contains the key/value pairs for each index in the array. {{InteractiveExample("JavaScript Demo: Array.prototype.entries()")}} ```js interactive-example const array = ["a", "b", "c"]; const iterator = array.entries(); console.log(iterator.next().value); // Expected output: Array [0, "a"] console.log(iterator.next().value); // Expected output: Array [1, "b"] ``` ## Syntax ```js-nolint entries() ``` ### Parameters None. ### Return value A new [iterable iterator object](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator). ## Description When used on [sparse arrays](/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays), the `entries()` method iterates empty slots as if they have the value `undefined`. The `entries()` method is [generic](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#generic_array_methods). It only expects the `this` value to have a `length` property and integer-keyed properties. ## Examples ### Iterating with index and element ```js 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 ```js const array = ["a", "b", "c"]; const arrayEntries = array.entries(); for (const element of arrayEntries) { console.log(element); } // [0, 'a'] // [1, 'b'] // [2, 'c'] ``` ### Iterating sparse arrays `entries()` will visit empty slots as if they are `undefined`. ```js for (const element of [, "a"].entries()) { console.log(element); } // [0, undefined] // [1, 'a'] ``` ### Calling entries() on non-array objects The `entries()` method reads the `length` property of `this` and then accesses each property whose key is a nonnegative integer less than `length`. ```js const arrayLike = { length: 3, 0: "a", 1: "b", 2: "c", 3: "d", // ignored by entries() since length is 3 }; for (const entry of Array.prototype.entries.call(arrayLike)) { console.log(entry); } // [ 0, 'a' ] // [ 1, 'b' ] // [ 2, 'c' ] ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Polyfill of `Array.prototype.entries` in `core-js`](https://github.com/zloirock/core-js#ecmascript-array) - [es-shims polyfill of `Array.prototype.entries`](https://www.npmjs.com/package/array.prototype.entries) - [Indexed collections](/en-US/docs/Web/JavaScript/Guide/Indexed_collections) guide - {{jsxref("Array")}} - {{jsxref("Array.prototype.keys()")}} - {{jsxref("Array.prototype.values()")}} - [`Array.prototype[Symbol.iterator]()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Symbol.iterator) - {{jsxref("TypedArray.prototype.entries()")}} - [Iteration protocols](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)