我通常遵循eslint AirBnB配置,我注意到我在使用For ... In循环时遇到了错误?为什么会这样?
我已经读了一下Here,但我想要更详细的解释或示例。
const data = {
color : 'blue',
movies : 'action',
hobby : 'football',
};
for (let prop in data) {
console.log(`prop: ${prop} and value is ${data[prop]}`);
}
//Throws Guarding for in, should be wrapped in an if statement to
//filter unwated properties from the prototype.
Object.keys(data).forEach((element) => {
console.log(`prop: ${element} and value is ${data[element]}`);
});
//This is Okay