JavaScript Array entries() Method

16 Jun, 2022
This article will cover all the facts in detail which are related to the method, namely Array.entries() under Arrays in JavaScript.
Let us have a look in the below illustrated example which shows the utilization of the Array entries() method.
Example: 
html
<!DOCTYPE html><html>    <body style="text-align: center;">        <h1 style="color: green;">          GeeksforGeeks        </h1>        <b>          JavaScript | Array entries() Method        </b>        <p id="geeks"></p>         <script>            var languages = ["HTML", "CSS",                             "JavaScript", "ReactJS"];            var g = languages.entries();             for (x of g) {                document.getElementById("geeks")                  .innerHTML += x + "<br>";            }        </script>    </body></html>
Output:
The Array.entries() method works on iterable objects such as an array (or any data iterable data structure) and it used to fetch all the entries of the same data structure. This method is used to get a new Array that contains the key and value pairs for each index of an array. 
Syntax:
array.entries()
Parameters: This method does not accept any parameter. 
Return value: It returns an array of indexes and values of the given array on which Array.entries() method is going to work. 
More example codes for the above method are as follows: 
Program 1: 
JavaScript
<script>    var arr = ["HTML", "CSS", "JS",               "Bootstrap", "PHP"];    var seqn = arr.entries();    document.write("Applying the Array entries method:"                   + "<br>");     for (var x of seqn) {        document.write(x + "</br>");    }</script>
Output:
Applying the Array entries method:
0,HTML
1,CSS
2,JS
3,Bootstrap
4,PHP
Program 2: 
JavaScript
<script>    const x = ["Geeks", "for", "Geeks"];     for (const [index, element] of x.entries())      document.write(index, element);</script>
Output:
0Geeks1for2Geeks
Program-3: In this example we will understand use of the above illustrated method in somehow different way using several other method which is next().
Javascript
let fruits_names = ['apple', 'banana', 'mango']; let fruits_array_iterator = fruits_names.entries(); console.log(fruits_array_iterator.next().value);console.log(fruits_array_iterator.next().value);
Output:
[ 0, 'apple' ]
[ 1, 'banana' ]
Supported Browsers: The browsers supported by JavaScript Array entries() method are listed below:
Google Chrome 38.0
Microsoft Edge 12.0
Mozilla Firefox 28.0
Safari 8.0
Opera 25.0
ManasChhabra2
amansingla
sumitgumber28
javascript-array
JavaScript-Methods
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Difference Between PUT and PATCH Request
Roadmap to Learn JavaScript For Beginners
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?