3 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是你想要的?
const firstObj = [
{ Id: "1", Name: "Peter" },
{ Id: "2", Name: "John" },
{ Id: "12", Name: "jessy" },
];
const secondObj = [
{ Id: "1", Name: "Roa", original: { Id: "1" } },
{ Id: "2", Name: "John2", original: { Id: "2" } },
{ Id: "1", Name: "Rachel", original: { Id: "3" } },
];
const result = lodash.filter(firstObj, (firstItem) => {
return !lodash.some(secondObj, (secondItem) => {
return firstItem.Id === secondItem.original.Id;
});
});
直播:https://stackblitz.com/edit/js-addy5t?file =index.js

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
為什么要為此使用 loadash。您可以使用本機(jī)過(guò)濾器并查找功能來(lái)實(shí)現(xiàn)此目的
const filter = firstObj.filter(item => { return secondObj.find(itm => itm.original.id === item.id) });

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
Array.filter()
您可以使用和的本地方法Array.some()
來(lái)實(shí)現(xiàn)所需的輸出。
請(qǐng)檢查下面的工作代碼片段
ES6
const firstObj = [
{ Id: "1", Name: "Peter" },
{ Id: "2", Name: "John" },
{ Id: "12", Name: "jessy" },
],
secondObj = [
{ Id: "1", Name: "Roa", original: { Id: "1" } },
{ Id: "2", Name: "John2", original: { Id: "2" } },
{ Id: "1", Name: "Rachel", original: { Id: "3" } },
];
let result = firstObj.filter(({Id})=> !secondObj.some(item => item.original.Id === Id));
console.log(result)
添加回答
舉報(bào)