English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The entries() method returns a new array iterator object that contains the keys at each index of the array/Pairs.
array.entries()
var fruits = ['Apple', 'Mango', 'Banana']; var iter = fruits.entries();Test and see‹/›
For each item in the original array, the new iterator object will contain an array with the index as the key and the item value as the value:
[0,“ Apple”]
[1,“Mango”]
[2,“Banana”]
The numbers in the table specify the first browser version that fully supports the entry() method:
Method | |||||
entries() | 38 | 28 | 25 | 8 | Yes |
Return Value: | A new Array iterator object |
---|---|
JavaScript Version: | ECMAScript 6 |
The following code uses the for...of loop to print the key/Value Pair:
var fruits = ['Apple', 'Mango', 'Banana']; var iter = fruits.entries(); for (let e of iter) { console.log(e); }Test and see‹/›