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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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);

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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);
}

chevron_right


Output:

> Array [0, \"geeksforgeeks\"]
> Array [1, \"gfg\"]
> Array [2, \"Jhon\"]


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.