I have 2 arrays (array1 and array2). I want to compare array1 and array2 by using 'id' as the key and want to create 2 resultant arrays out of array2.
- First array should contain all the objects which is present in array2 but not in array1.
- Second array should contain all the objects which is present in array1 and array2 both, common ones.
const array1 = [{ id: 176770 }, { id: 176771 }, { id: 176820 }];
const array2 = [
{ id: 176770, classfication: "comeone", type: "typeee" },
{ id: 176771, classfication: "comeone1", type: "typeee1" },
{ id: 176820, classfication: "comeone2", type: "typeee2" },
{ id: 176670, classfication: "comeone", type: "typeee" },
{ id: 176761, classfication: "comeone1", type: "typeee1" },
{ id: 176845, classfication: "comeone2", type: "typeee2" },
];
Please help me out to create these 2 arrays.