[英]Expected to return a value at the end of arrow function. (consistent-return)
in my code, I want to iterate over an array of objects, as soon as one of these objects contains the element return true otherwise at the end of loop return false. 在我的代码中,我想遍历对象数组,一旦这些对象之一包含元素返回true,否则在循环结束时返回false。 it seems that my code works but ESLint shows error
[eslint] Expected to return a value at the end of arrow function. (consistent-return)
似乎我的代码有效,但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)
but I don't want to return for instance false
if the condition is false. [eslint] Expected to return a value at the end of arrow function. (consistent-return)
但我不希望返回例如false
,如果条件为假。
so my array looks like below. 所以我的数组如下所示。 and the function afterward.
之后的功能。
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;
}
It appears that you want to determine if the statements is true for at least one item. 您似乎想要确定至少一项的陈述是否正确。
You should use the some function. 您应该使用一些功能。
This stops looking after it has found the first match. 找到第一个匹配项后,它将停止寻找。
isOccupied(row, col) {
const { myArray} = state[id];
return myArray.some(key => key.location.includes(row+col));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.