javascript 中的 for in遍历属性问题

2025-05-18 10:38:46
推荐回答(1个)
回答1:

p是从str中遍历出的属性名,是个字符串,不是数组,要调用它直接用p即可,而str[p]则是遍历出的每个属性值:

for(p in str){
    console.log("属性名:"+p);
    console.log("属性值:"+str[p]);
}