我的array.filter语法有什么问题? [英] What's wrong with my array.filter syntax?
本文介绍了我的array.filter语法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this.firmCategories = this.firmCategories.filter(x => {
x.id !== firmCatId;
});
通过调试器,我可以看到firmCategories数组中有一个具有匹配ID的元素,但是执行此操作后,我会得到一个完全空的数组.
I can see that there is one element of the firmCategories array that has the matching ID by using my debugger, however, I am left with a completely empty array after this executes.
我希望除具有剩余匹配ID的元素外,其他所有元素.怎么了?
I would expect to have every element except for the one that has the matching ID leftover. What's up?
推荐答案
您缺少 return
语句.
this.firmCategories = this.firmCategories.filter(x => {
return x.id !== firmCatId;
});
或者采用没有功能主体的箭头功能.
Or take an arrow function without a function body.
this.firmCategories = this.firmCategories.filter(x => x.id !== firmCatId);
这篇关于我的array.filter语法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文