js: for in 循环对象

var peopleObj = {
    'man': ['2', '2', '2'],
    'woman': ['1', '1', '1'],
    'womanDoctor': ['100', '100', '100']
}
for(const prop in peopleObj){
    if(peopleObj.hasOwnProperty(prop)){
        console.log(peopleObj[prop])
        // can reset prop's value
        peopleObj[prop] = ['1000', '1000', '1000'];
    }
}
console.log(peopleObj);

运行结果如下图

js: for in 循环对象_第1张图片

 

你可能感兴趣的:(javascript,javascript,前端)