Question: 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

Answer: 
try 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' }
  ]

const array2Names = array2.map(e => e.name)

const arrayYouWant = array1.filter(e => array2Names.includes(e.name) === false)

```

The array2Names variable return an array like this : `['A','B']`
The includes method allows us to know if the analyzed array contains the element in parentheses.
We can use [Array.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/finlter) and [Array.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) to get all the objects in array1, but not in array2.

We use .filter to find all the items in array1 that are not present in array2, using .find.

```js
const array1 = [
    { id: 1, name: 'A' },
    { id: 2, name: 'B' },
    { id: 3, name: 'C' }
]

const array2 = [
    { id: 1, name: 'A' },
    { id: 2, name: 'B' }
]

const diff = array1.filter(x1 => !array2.find(x2 => {
    return x1.id === x2.id && x1.name === x2.name;
}));

console.log(diff);
```