p是从str中遍历出的属性名,是个字符串,不是数组,要调用它直接用p即可,而str[p]则是遍历出的每个属性值:
for(p in str){ console.log("属性名:"+p); console.log("属性值:"+str[p]);}