// Sample arrays
const array1 = [
{ id: 1, name: 'Apple' },
{ id: 2, name: 'Banana' },
{ id: 3, name: 'Orange' },
];
const array2 = [
{ id: 2, name: 'Banana' },
{ id: 4, name: 'Grapes' },
];
// Get differences based on the 'id' property
const differences = array1.filter(item1 => !array2.some(item2 => item2.id === item1.id));
console.log(differences);
output:
[
{ id: 1, name: 'Apple' },
{ id: 3, name: 'Orange' }
]
Subscribe
Login
0 Comments