1)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript">
function fun()
{//利用for...in的循环机制来遍历对象的所有属性
var obj=new Object();
obj.title="javascript";
obj.author="自在飞花轻似梦";
obj.sex="男";
for(prop in obj)
{//一次输出 obj对象的每一个属性
console.log("obj."+prop+"="+obj[prop]);
}
}
fun();
</script>
</head>
<body>
<h1>New Web Project Page</h1>
</body>
</html>
输出: