我有一个对象数组:
const array = [{id: 1, bar: "test" }, {id: 2, bar: "test2" }, {id: 3, bar: "test3" }]
我有第二个数组,其中包含要从第一个数组中过滤掉的 ID:const ids = [1, 2]
如何在没有 ids
中找到的 ID 的情况下创建新的对象数组.
最佳答案
这是一个相当简单的filter
手术
const array = [{id: 1, bar: "test" }, {id: 2, bar: "test2" }, {id: 3, bar: "test3" }];
const ids = [1, 2];
var result = array.filter( x => !ids.includes(x.id));
console.log(result);
关于javascript - 如何用另一个数组过滤一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63380584/