在我的代码中,我想迭代一个对象数组,只要其中一个对象包含该元素返回true,否则在循环结束时返回false。似乎我的代码工作,但ESLint显示错误[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;
}
看来你想确定这些陈述是否适用于至少一个项目。
你应该使用some函数。
这停止了它找到第一场比赛后的照顾。
isOccupied(row, col) {
const { myArray} = state[id];
return myArray.some(key => key.location.includes(row+col));
}