![](/img/trans.png)
[英]Expected to return a value at the end of arrow function consistent-return
[英]Expected to return a value at the end of arrow function. (consistent-return)
在我的代碼中,我想遍歷對象數組,一旦這些對象之一包含元素返回true,否則在循環結束時返回false。 似乎我的代碼有效,但ESLint顯示錯誤[eslint] Expected to return a value at the end of arrow function. (consistent-return)
[eslint] Expected to return a value at the end of arrow function. (consistent-return)
但我不希望返回例如false
,如果條件為假。
所以我的數組如下所示。 之后的功能。
myArray:[{location:["rowcol","rowcol",...]},{location:[]},{location:[]},...]
isOccupied(row, col) {
const { myArray} = state[id];
myArray.forEach(key => { // here on arrow I see the error
if(key.location.includes(row+ col)) return true;
});
return false;
}
您似乎想要確定至少一項的陳述是否正確。
您應該使用一些功能。
找到第一個匹配項后,它將停止尋找。
isOccupied(row, col) {
const { myArray} = state[id];
return myArray.some(key => key.location.includes(row+col));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.