What is for...in loop statement in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The for...in loop is used to loop through an object's properties. 

Syntax

Here’s the syntax −

for (variablename in object){
   statement or block to execute
}

Example

Try the following example to implement ‘for-in’ loop. It prints the web browser’s Navigator object

Live Demo

<html>
   <body>
      <script>
         var aProperty;
         document.write("Navigator Object Properties<br /> ");
         
         for(aProperty in navigator) {
            document.write(aProperty);
            document.write("<br />");
         }
         document.write ("Exiting from the loop!");
      </script>
   </body>
</html>
raja
Published on 19-Jan-2018 11:08:57
Advertisements