How to use for...in statement to loop through an Array in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The for...in loop is used to loop through an object's properties. Let’s see a for…in statement to loop through an array.

Example

You can try to run the following code to learn how to use the for…in statement to loop through an array −

Live Demo

<html>
   <body>
      <script>
         var items = new Array('Hello', 'World');
         var i = 0;

         for (var i in items) {
            document.write(items[i]);
         }
      </script>
   </body>
</html>
raja
Published on 19-Jan-2018 06:45:33
Advertisements