javascript中遍历对象属性与属性值

时间:2022-04-01 04:14:18
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>javascript中遍历对象属性与属性值</title>
<script type="text/javascript">
<!--
var Monitor={
price:18,
factory:"远航公司",
type:"B2",
size:19
};
document.write("遍历对象属性:","<br/>");
for(var obj in Monitor)
{
document.write(obj,"<br/>");
}
document.write("遍历对象属性值:","<br/>");
for(var obj in Monitor)
{
document.write(obj,"-->",Monitor[obj],"<br/>");
}
-->
</script>
</head>
<body>
</body>
</html>

相关文章