| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The entries() method of Array instances returns a new array iterator object that contains the key/value pairs for each index in the array.
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"]
entries()
None.
A new iterable iterator object.
When used on sparse arrays, the entries() method iterates empty slots as if they have the value undefined.
The entries() method is generic. It only expects the this value to have a length property and integer-keyed properties.
const a = ["a", "b", "c"];
for (const [index, element] of a.entries()) {
console.log(index, element);
}
// 0 'a'
// 1 'b'
// 2 'c'
const array = ["a", "b", "c"];
const arrayEntries = array.entries();
for (const element of arrayEntries) {
console.log(element);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']
entries() will visit empty slots as if they are undefined.
for (const element of [, "a"].entries()) {
console.log(element);
}
// [0, undefined]
// [1, 'a']
The entries() method reads the length property of this and then accesses each property whose key is a nonnegative integer less than length.
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' ]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.entries |
Array.prototype.entries in core-jsArray.prototype.entriesArrayArray.prototype.keys()Array.prototype.values()Array.prototype[Symbol.iterator]()TypedArray.prototype.entries()This page was last modified on Jul 20, 2025 by MDN contributors.
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |