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.
```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 arr = [... new Set(array1.filter(el => !array2.some(el2 => el2.id == el.id)))];
  console.log(arr);
```