我有一個對象ESLint不允許在
currentValues= {hey:1212, git:1212, nmo:12121}
,我在使用這樣的:
for (const key in currentValues) {
if (Object.prototype.hasOwnProperty.call(currentValues, key)) {
yield put(setCurrentValue(key, currentValues[key]));
}
}
ESLint顯示我這是說的錯誤:
ESLint:for..in循環遍歷整個原型鏈,這實際上從來不是你想要的。使用對象{鍵,值,條目},並遍歷結果數組。 ?(沒有限制的語法
應該如何修改我的代碼
嘗試'爲(currentValues.keys的常量鍵())'corrent如果你只需要按鍵。如果你需要鍵和值,你可以使用'entries'。 – Li357
@AndrewLi你在談論Object.keys()嗎?如果是這樣,那麼它就會成爲問題,因爲用'for ... in'來遍歷一個數組是不被接受的。 – Pointy
@Pointy我正在使用'for ... of'? – Li357