Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Array entries() Method

  • Difficulty Level : Basic
  • Last Updated : 23 Jun, 2020

Below is the example of the Array entries() method.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:




    <!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 lnaguages = ["HTML", "CSS", 
                                 "JavaScript", "ReactJS"];
                var g = lnaguages.entries();
      
                for (x of g) {
                    document.getElementById("geeks")
                      .innerHTML += x + "<br>";
                }
            </script>
        </body>
    </html>
  • Output:

The arr.entries() 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 arr.entries() method is going to work.

More example codes for the above method are as follows:

Program 1:




<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:




<script>
    const x = ["Geeks", "for", "Geeks"];
  
    for (const [index, element] of x.entries()) 
      document.write(index, element);
</script>

Output:

0Geeks1for2Geeks

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :