JavaScript Array entries()
- Previous Page copyWithin()
- Next Page every()
- Go to the Previous Level JavaScript Array Reference Manual
Definition and Usage
entries()
The 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"]
Note:entries()
It will not change the original array.
Example
Create an Array Iterator object and create a loop to iterate over each key/value pair:
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var f = fruits.entries(); for (x of f) { document.getElementById("demo").innerHTML += x; }
Syntax
array.entries()
Parameters
No parameters.
Technical Details
Return Value: | Array Iterator Object |
---|---|
JavaScript Version: | ECMAScript 6 |
Browser Support
The numbers in the table indicate the first browser version that fully supports this method.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 38 | Edge 12 | Firefox 28 | Safari 8 | Opera 25 |
October 2014 | July 2015 | March 2014 | October 2014 | October 2014 |
Note:Internet Explorer does not support entries()
Methods.
Related Pages
Tutorial:JavaScript Array
Tutorial:JavaScript Array Const
Tutorial:JavaScript Array Methods
Tutorial:JavaScript Sort Array
Tutorial:JavaScript Array Iteration
- Previous Page copyWithin()
- Next Page every()
- Go to the Previous Level JavaScript Array Reference Manual