var abc = {
name:"abc",
age:12,
sex:"m"
};
for(attr in abc){
console.log("abc属性:"+attr);//attr为abc的属性
console.log("abc["+attr+"]:"+abc[attr]);//abc[attr]为abc的属性attr的值
}
/*
*输出结果:
*abc属性:name
*abc[name]:abc
*abc属性:age
*abc[age]:12
*abc属性:sex
*abc[sex]:m
*/
http://www.studyer.com/%E8%8E%B7%E5%8F%96javascript%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%80%E6%9C%89%E5%B1%9E%E6%80%A7%E5%92%8C%E5%80%BC/
获取JavaScript自定义对象的所有属性和值
最新推荐文章于 2024-06-20 14:49:10 发布