我有一个对象
currentValues= {hey:1212, git:1212, nmo:12121}
我这样使用 for :
for (const key in currentValues) {
if (Object.prototype.hasOwnProperty.call(currentValues, key)) {
yield put(setCurrentValue(key, currentValues[key]));
}
}
ESLint 向我显示了一个错误,内容是:
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
我应该如何编辑我的代码?
最佳答案
它说,
Use Object.{keys,values,entries}, and iterate over the resulting array.
因此,您可以执行类似的操作来获取对象键作为数组,然后循环遍历键以进行必要的更改。
currentValues= {hey:1212, git:1212, nmo:12121}
Object.keys(currentValues).forEach(function(key) {
yield put(setCurrentValue(key, currentValues[key]));
})
关于javascript - ESLint 不允许 in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43807515/