I have an object with some keys and values.
I initially had this loop:
for(const key in commands) {
if (commands.hasOwnProperty(key)) {
const value = commands[key];
// Do something else
}
}
That gave me the following eslint error:
for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array. (no-restricted-syntax)
So I changed it to this:
Object.keys(commands).forEach(key => {
if (commands.hasOwnProperty(key)) {
const value = commands[key];
}
});
Now, I'm getting the following error due to hasOwnProperty:
Do not access Object.prototype method 'hasOwnProperty' from target object. (no-prototype-builtins)
How can I write a simple loop that iterates over the keys whilst avoiding eslint errors?