2 回答
TA贡献1842条经验 获得超21个赞
尝试这样的事情:
const arr1 = [{
"number": "1234",
"id": "34782",
"firstName": "John",
"lastName": "Smith",
"email": "test1@test.com",
},
{
"number": "1232",
"id": "34783",
"firstName": "Chad",
"lastName": "Baker",
"email": "test2@test.com",
}
];
const arr2 = [{
"uuid": "0123",
"firstName": "John",
"lastName": "Smith",
"title": "Director"
},
{
"uuid": "0125",
"firstName": "Sam",
"lastName": "Hurst",
"title": "Manager"
}
]
const arr3 = arr1.filter(value =>
arr2.some(value2 =>
value.firstName === value2.firstName && value.lastName === value2.lastName
)
);
console.log(arr3);
TA贡献1829条经验 获得超6个赞
我认为您可以尝试以下方法:
arr1.filter(item1 => (arr2.find(item2 => (item2.firstName == item1.firstName && item2.lastName == item1.lastName)) != undefined));
它使用arr2.find函数检查它是否包含某些具有相同firstName和lastName属性的项目。
添加回答
举报