Get value not in array

Viewed 1781

Given two arrays: (one and two).

one: contains values

two: contains objects with values

I need to get the values from one which are not in two. I've tried with .filter() and .indexOf() but don't get the desired result.

In the following case I expect result to have the value 333. How to achieve that?

var one = [111, 222, 333, 444];
var two = [
  { identifier: 111 },
  { identifier: 222 },
  { identifier: 444 }
];

var result = two.filter(function (item) {
    console.log(item.identifier, one.indexOf(item.identifier));
});

console.log('result: ', result);

8 Answers
Related