Javascript 数组与包含相反
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48592791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 08:07:25 来源:igfitidea点击:
Javascript Arrays Opposite of Includes
提问by lost9123193
What is the correct way of removing objects that have a certain field in JavaScript?
在 JavaScript 中删除具有特定字段的对象的正确方法是什么?
I can include fields with the following:
我可以包含以下字段:
filteredResult = filteredResult.filter(e => e.selectedFields.includes("Red"));
But if I wanted to remove all properties that have this field what would I do? There doesn't seem to be a "Remove" from the documentation.
但是,如果我想删除所有具有此字段的属性,我会怎么做?文档中似乎没有“删除”。
回答by tremby
Just negate it.
就否定它。
filteredResult = filteredResult.filter(e => !e.selectedFields.includes("Red"))

