JavaScript entries() | Convert an Array to an Iterator Object

The JavaScript entries() method returns an object Array Iterator that will obviously in key/value pairs. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <script>
      const a = ["Berlin", "Vancouver", "Tokyo", "NYC"];

      const b = a.entries();
      
      for(let x of b)
      {
         document.write(x);
         document.write("<BR>");
      }
   </script>
   
</body>
</html>

The snapshot given below shows the sample output produced by above JavaScript example:

javascript entries

Note - The for...of loop is used to loop through the values of an iterable object.

JavaScript entries() Syntax

The syntax of entries() method in JavaScript is:

array.entries()

JavaScript Online Test


« Previous Tutorial Next Tutorial »



Like/Share Us on Facebook 😋