I have tow arrays of object like this :
const array1 = [
{ id: 1, name: 'A' },
{ id: 2, name: 'B' },
{ id: 3, name: 'C' }
]
const array2 = [
{ id: 1, name: 'A' },
{ id: 2, name: 'B' }
]
I want another array from arry1 which contains those objects which are not in array2. like this :
[{ id: 1, name: 'C' }]
I tried this approach : var finalArray = array1.filter(function (obj) { return array2.indexOf(obj) === -1; });
But its not working. Please help me