I have an array of values, for example:
let values = [1, 2, 3, 4, 5];
And I have another array, containing objects, for example:
let objects = [{name: 'Dennis', value: 2}, {name: 'Charlie', value: 4}];
I would like to produce an array that only contains values that aren't present in the value property of my objects.
So from the examples above, I would return an array of [1, 3, 5]
What I've got at the moment is:
let missingValues = [];
for (let i = 0; i < values.length; i++) {
if (!objects.filter(obj => obj.value === values[i]) {
missingValues.push(values[i]);
}
}
This works, but feels slightly messy, is there a more efficient way to do this?