I have a couple of JS objects like these:
var formulas = [
{formulaID: 1, lastManufactureDate: '2020-03-24'},
{formulaID: 3, lastManufactureDate: '2020-03-20'},
{formulaID: 7, lastManufactureDate: '2020-03-16'},
{formulaID: 9, lastManufactureDate: '2020-03-20'}
];
var allFormulas = [
{formulaID: 1, formulaName: 'Chocolate Milk 2%'},
{formulaID: 2, formulaName: 'Chocolate Milk 1%'},
{formulaID: 3, formulaName: 'Vanilla Creamer'},
{formulaID: 4, formulaName: 'Hazelnut Creamer'},
{formulaID: 5, formulaName: 'Plain Creamer'},
{formulaID: 6, formulaName: 'White Milk 2%'}
];
I need to find a way to identify all the objects in the formulas
array which have formulaIDs that do not exist in the allFormulas
array. Basically, the equivalent of doing a LEFT OUTER JOIN with a WHERE clause to find NULLs on the right hand side. In the sample data here, the expected output would be [{formulaID: 7, lastManufactureDate: '2020-03-16'}, {formulaID: 9, lastManufactureDate: '2020-03-20'}]
In the app the number of objects in the formulas
array is about 135 and in the allFormulas
array there are around 1,100.
The goal is to do this efficiently and without a third party library. I found a similar question here but it didn't address identifying the objects in one array that aren't in the other. Unfortunately, I don't really know where to start to solve this problem.