Javascript 如何在外部函数上返回true

Javascript 如何在外部函数上返回true,javascript,return,Javascript,Return,对于下面的示例,如何有条件地从forEach函数检查并返回true?谢谢 this.results.forEach(el => { el.forEach(el => { if (el == 3) { //return true here is not working } }) }); if (this.SlantLeft == 3 || this.SlantRight == 3) { return true //like this }

对于下面的示例,如何有条件地从
forEach
函数检查并返回
true
?谢谢

this.results.forEach(el => {
  el.forEach(el => {
    if (el == 3) {
      //return true here is not working  
    }
  })
});

if (this.SlantLeft == 3 || this.SlantRight == 3) {
  return true //like this
}

我认为您需要
some()
,如果任何iterable元素满足条件,它将返回true,否则返回false

this.results.some(el => el == 3);

您是否有一些数据要测试和想要的结果?您不能,forEach会忽略其回调的返回值。也许你想要。改为查找?与return一起使用或使用OK谢谢。这很好,但当我处理一个数组时,当数组中有数组时,如何执行此操作?你为…of添加嵌套的
,就像为每个数组添加嵌套的
<如果(n===3)返回true,则(让el表示这个.results)的(让n表示el)的code>for(让n表示el)的
(您已经将forEach回调的两个参数都命名为
el