運用in運算子來穫取未知對象屬性以及屬性值
var obj = new Object(); obj.attr1="1111" obj.attr2="2222" alert(obj.attr1); alert(obj.attr2); for(attribute in obj){ var attrName = attribute;//屬性名稱 alert(attrName); var value = null; eval("value=o."+attrName);//屬性值 alert(value); } 用in運算子判斷物件是否有此屬性 console.log(attr in obj);