JavaScript Array entries()
Example
Create an Array Iterator, and then iterate over the key/value pairs:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const f = fruits.entries();
for (let x of f) {
document.getElementById("demo").innerHTML += x;
}
Try it Yourself »
Definition and Usage
The entries() method returns an Array Iterator object with key/value pairs.
For each item in the original array, the new iteration object will contain an array with the index as the key, and the item value as the value:
[0, "Banana"]
[1, "Orange"]
[2, "Apple"]
[3, "Mango"]
entries() does not change the original array.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
| Chrome 38 | Edge 12 | Firefox 28 | Safari 8 | Opera 25 |
| Oct 2014 | Jul 2015 | Mar 2014 | Oct 2014 | Oct 2014 |
entries() is not supported in Internet Explorer.
Syntax
array.entries()
Parameter Values
No parameters.
Technical Details
| Return Value: | An Array Iterator object |
|---|---|
| JavaScript Version: | ECMAScript 6 |

