简体   繁体   English

预期在箭头函数的结尾处返回一个值。 (一致返回)

[英]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.

相关问题 预期在箭头函数的末尾返回一个值consistent-return - Expected to return a value at the end of arrow function consistent-return Firebase云功能警告:“箭头功能预期没有返回值一致 - 返回” - Firebase Cloud Functions warning: “Arrow function expected no return value consistent-return” 使用简单箭头 function 修复“一致返回”linter 问题 - Fixing 'consistent-return' linter issue with simple arrow function 预期在箭头函数中返回一个值。 (xo代码样式) - Expected to return a value in arrow function. (xo code style) JavaScript,预期在箭头函数的末尾返回一个值 - JavaScript, Expected to return a value at the end of arrow function 错误预期在箭头函数的末尾返回一个值 - Error Expected to return a value at the end of arrow function 预期在箭头函数错误的末尾返回一个值 - Expected to return a value at the end of arrow function error 预期在react中的箭头函数末尾返回一个值 - Expected to return a value at the end of arrow function in react 重构:期望在箭头函数的末尾返回一个值 - Refactor: Expected to return a value at the end of arrow function 预计在箭头 function 的末尾使用 if 语句返回一个值 - Expected to return a value at the end of arrow function with if statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM