let array = [
{name: "60", origin: "tcs"},
{name: "70", origin: "cfs"},
{name: "80", origin: "ehg"},
]
undefined
let def = [
{id: "60", testorigin: "tcs"},
{id: null, testorigin: "cfs"}, // this line should be removed
{id: "80", testorigin: "ehg"},
]
输出
[
{name: "60", origin: "tcs"},
{name: "80", origin: "ehg"},
]
我只想删除def的第二个元素,因为它的id为null,并且它与array的名称不匹配。
我试过很多方法,但都失败了,先谢谢你了。
2条答案
按热度按时间dw1jzc5e1#
这是解决方案。你只需要检查两个对象的条件相同的索引。这个答案会帮助你。
谢谢!
bejyjqdl2#
你可以这样做: