过滤器功能不返回值

时间:2018-08-03 09:17:05

标签: javascript

我将使用JS中的过滤器过滤对象列表

dataid

我的elm.identifiant == this.dataService.getcurrentId()为空,而true在给定时刻为option[selected]

2 个答案:

答案 0 :(得分:2)

functional-programming无关。尝试下面的代码

let f = a => { a == 1 };
f(1); // undefined
let g = a => a == 1;
g(1); // true
let h => a => { return a == 1; };
h(1); // true

最好不要使用内联函数来调试高阶函数。

答案 1 :(得分:1)

对于unsigned char中的多行代码,您需要明确提及Array.filter()。对于return这样的单行,我们不指定infosStructured.filter((elm) => elm)关键字。

return

如果您不需要在过滤器中使用let dataid = infosStructured.filter(elm => { console.log(elm.identifiant); console.log("matching value", elm.identifiant == this.dataService.getcurrentId()); // I get a true value elm.identifiant == this.dataService.getcurrentId(); return elm; }); console.log(dataid); ,则可以在不使用console.log()关键字的情况下将其更改为:

return