I have two arrays of objects. I would like to use JavaScript to create a new array which does not contains object that match by id field.
First array
[{id: 1, name: "Jo"},{id: 2, name: "Pat"},{id: 3, name: "Mike"}]
Second array
[{id: 1, name: "Jo"},{id: 2, name: "Pat"},{id: 3, name: "Mike"}, {id: 4, name: "Mitch"}, {id: 5, name: "Karl"}]
should return this array
[{id: 4, name: "Mitch"}, {id: 5, name: "Karl"}]
Using lodash would be better if possible. Please note that the first array is always smaller or equal to the second one and can only contain objects that are in the second one.
So I tried the following...
let newArray = _.reject(secondArray, {'id': firstArray});
Without success, I need help with the syntax.
Many thanks for your time and help.