我会使用 JS 中的过滤器来过滤对象列表
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();
});
console.log(dataid); // empty
我的 dataid
为空,而 elm.identifiant == this.dataService.getcurrentId()
在给定时刻为 true
最佳答案
它与函数式编程
无关。尝试下面的代码
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
最好不要使用内联函数来调试高阶函数。
关于javascript - 过滤函数不返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51669283/