我试图从包含稍微不同的对象的2个不同的数组中找到交集。
例如:
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(object => arr2.includes(object));
console.log(arr3);
我试图创建一个只包含的对象一个新的数组arr1,其中firstName和lastName值在两个数组相同。
上述数据的期望结果:
arr3 = [
{
"number":"1234",
"id":"34782",
"firstName":"John",
"lastName":"Smith",
"email":"test1@test.com",
},
]
因为此对象的firstName和lastName都匹配,arr1并且arr2
现在我有 this.arr3 = this.arr1.filter(object => this.arr2.includes(object))
但是由于专有名称导致arr1和arr2包含不同的对象,所以这是行不通的。
茅侃侃
肥皂起泡泡
相关分类