Use _.differenceBy() to find items in the 1st array (allCodes
) that are not found in the 2nd array (balanceCodes
):
var balanceCodes = [
{ ID: 1, StringValue: "dummy" },
{ ID: 2, StringValue: "data" }
];
var allCodes = [
{ ID: 1, StringValue: "dummy", Color: "red", Order: "low" },
{ ID: 2, StringValue: "data", Color: "green", Order: "medium" },
{ ID: 3, StringValue: "extra", Color: "black", Order: "low" },
{ ID: 4, StringValue: "options", Color: "grey", Order: "high" }
];
var result = _.differenceBy(allCodes, balanceCodes, 'ID');
console.log(result);