for…in循环的Javascript示例:
<html>
<head>
<title>一个使用到for…in循环的Javascript示例</title>
</head>
<body>
<script type=”text/javascript”>
// 创建一个对象 myObject 以及三个属性 sitename, siteurl, sitecontent。
var myObject = new Object();
myObject.sitename = “布啦布啦”;
myObject.siteurl = “mrtemp.net”;
myObject.sitecontent = “Mrtemp关注web开发”;
//遍历对象的所有属性
for (prop in myObject)
{
document.write(“属性 ‘“ + prop + “‘ 为 “ + myObject[prop]);
document.write(“<br>”);
}
</script>
</body>
</html>
js 中遍历属性名和值
坚持原创分享,您的支持将鼓励我继续创作!
- Post link: https://lifesign.me/2012/04/23/js-for-in/
- Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.