for...in...这个结构不少语言里有,大体相似,主要是枚举一些对象。
 
for(myvar  in  obj)...
 
这里myvar使一些可以做左值的变量,比如一个变量,一个var myvar的声明语句,数组元素等。
 
每次枚举过程会把obj的属性名的字符串赋给myvar.
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>for/in</title>
    <script text="text/javascript">
        var obj={x:1,y:2,z:3};
        for(var prop in obj)
        {
            document.write(prop+":"+obj[prop]+"<br/>");
        }
    </script>
    </head>
    <body>

    </body>
</html>
 
2.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>for/in</title>
    <script text="text/javascript">
        var obj={x:1,y:2,z:3};
        var arr=[];
        var i=0;
        for(arr[i++] in obj)/*空语句*/;
        
        alert(arr);//x,y,z
    </script>
    </head>
    <body>

    </body>
</html>
 
很适合那些属性个数不明朗的对象等的枚举