This comparison is a bit odd as I have the following format:
Preferences Object:
{
models: [
{... attributes: {} },
{... attributes: {} },
{... attributes: {} }
]
}
Data Array:
[{}, {}, {}]
I have this object that contains an array of more objects with a key called attributes.
My Goal:
My goal is to see which items in the Data Array don't exist as the value to the attributes key in the models array using Underscore.JS.
Hacky Attempt:
This is definitely not how I want to code this, but localStorageLayers is the Data Array and the layerPrefs is the Preferences Object is the above labelling.
_.each(localStorageLayers, (localLayer) => {
var layerWasLoaded = false;
_.each(layerPrefs.models, (layerPref) => {
if (_.isEqual(layerPref.attributes, localLayer)) {
layerWasLoaded = true;
// Don't do anything
}
})
if (layerWasLoaded == false) {
// Do stuff
}
})