• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

The for…in Loop

Closely allied to the for loop is the for…in loop, which iterates a variable over all the properties of an object. For each property, JavaScript executes the statements in the loop’s body. That might sound a little dry, but in fact, it’s a great help when you want to find out which properties are available to you in a specific object, such as some unknown browser’s document object. It’s also handy because you can iterate over all the properties in an object without even knowing how many properties there are, because the loop handles that automatically. Here’s the syntax of this loop:

for (variable in object) { 
    statements 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint