JavaScript | array.entries() Method
The array.entries() is an inbuilt function in JavaScript which is used to get a new Array that contains the key and value pairs for each index of an array.
Syntax:
array.entries();
Return value:
It returns an array of index and values of the given array on which array.entries() function is going to work.
Browser Support:
Here 2nd column contain int values that are version of the corresponding browser.
| Feature | Basic support |
|---|---|
| Chrome | 38 |
| Edge | Yes |
| Firefox | 28 |
| Internet Explorer | No |
| Opera | 25 |
| Safari | 8 |
| Android webview | Yes |
| Chrome for Android | Yes |
| Edge mobile | Yes |
| Firefox for Android | 28 |
| Opera Android | Yes |
| iOS Safari | 8 |
Examples:
Here array.entries() method in javaScript used to find out key and value pairs for each index in any given array.
Let\’s see JavaScript program:
var array = [\'geeksforgeeks\', \'gfg\', \'Jhon\']; var iterator = array.entries(); // expected output: Array [0, \"geeksforgeeks\"] console.log(iterator.next().value); // expected output: Array [1, \"gfg\"] console.log(iterator.next().value); // expected output: Array [2, \"Jhon\"] console.log(iterator.next().value); |
Output:
> Array [0, \"geeksforgeeks\"] > Array [1, \"gfg\"] > Array [2, \"Jhon\"]
Application:
Whenever we need to get key and value pair for each index in any array thet time we use array.entries() Method
Let\’s see JavaScript program:
var array = [\'geeksforgeeks\', \'gfg\', \'Jhon\']; var iterator = array.entries(); // printing key and value pair from the given // array using for loop. for (let e of iterator) { console.log(e); } |
Output:
> Array [0, \"geeksforgeeks\"] > Array [1, \"gfg\"] > Array [2, \"Jhon\"]
Recommended Posts:
- JavaScript | Array.from() method
- JavaScript | Replace() Method
- JavaScript | Array map() Method
- JavaScript | getTime() Method
- JavaScript | Array from() Method
- JavaScript | compile() Method
- JavaScript | Sort() method
- JavaScript | exec() Method
- JavaScript | Array.find() Method
- JavaScript | Array.findIndex() Method
- JavaScript | Array.splice() Method
- JavaScript | Array.fill() Method
- JavaScript | String includes() Method
- JavaScript | date.getDay() method
- JavaScript | Array reduce() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



