How to use for in statement in Javascript

Description

The for-in statement is used to enumerate the properties of an object. Here's the syntax:


for (property in expression) 
   statement

Example

The for-in statement is used to display all the properties of the BOM window object.


<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        for (var propName in window) { 
            document.writeln("<br/>"+propName); 
        } 
    </script>
</head>
<body>
</body>
</html>

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions