箭头功能过滤器

时间:2020-07-15 17:42:20

标签: javascript arrays ecmascript-6 filter arrow-functions

我不知道为什么会这样:

const numbers2 = [45, 5, 9, 16, 25];

const myFunction1 = (numbers2) =>{numbers2.filter(number=>{return number>6})}; 

console.log("Soy filter con arrowFunction: " + myFunction1(numbers2)); // Soy filter con arrowFunction: undefined

1 个答案:

答案 0 :(得分:1)

您缺少回报。参见下面添加的代码。

const numbers2 = [45, 5, 9, 16, 25];

const myFunction1 = (numbers2) =>{
  return numbers2.filter(number=>{   // <===== missing return was here
    return number>6
  }
  )
};

console.log("Soy filter con arrowFunction: " + myFunction1(numbers2));