JavaScript Array entries() Method
Example
Create an Array Iterator object, and create a loop that iterates each key/value pair:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var f =
fruits.entries();
for (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"]
Note: This method does not change the original array.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
entries() | 38.0 | 12.0 | 28.0 | 8 | 25.0 |
Syntax
array.entries()
Parameter Values
No parameters.
Technical Details
Return Value: | An Array Iterator object |
---|---|
JavaScript Version: | ECMAScript 6 |
Related Pages
JavaScript Tutorial: JavaScript Arrays
JavaScript Tutorial: JavaScript Array Iteration