let existing_array = [
{name: "a", age: 15},
{name: "b", age: 16},
{name: "c", age: 17},
{name: "d", age: 18}
{name: "e", age: 19}];
现在我有一个新数组
let new_array = = [
{name: "f", age: 15},
{name: "b", age: 16},
{name: "g", age: 17},
{name: "h", age: 18}
{name: "i", age: 19}];
现在existing_array和new_arrray都具有名称值'b',我希望将其从新数组中删除
答案 0 :(得分:1)
将filter()
与find
结合使用:
new_array = new_array.filter(x => !existing_array.find(y => x.age === y.age && x.name === y.age))
您可能想使用更好的相等性检查。