I have an object
currentValues= {hey:1212, git:1212, nmo:12121}
and I use for in like this:
for (const key in currentValues) {
if (Object.prototype.hasOwnProperty.call(currentValues, key)) {
yield put(setCurrentValue(key, currentValues[key]));
}
}
ESLint shows me an error which is saying:
ESLint: 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
How should I edit my code?
for(const key of currentValues.keys())if you only need the keys. You can useentriesif you need the keys and values.Object.keys()? If so, it'd stiill be questionable, since iterating through an array withfor ... inis frowned upon.for...of?.keys()function on that object.for inwas terrible, why can't they deprecate it 😡