I have two identical arrays of objects.
I then add an object to one of the arrays at a random index:
Arr1 = [{ id: "a" }, { id: "b" }, { id: "c" }]
Arr2 = [{ id: "a" }, { id: "d" }, { id: "b" }, { id: "c" }]
How would I go about comparing the two arrays, extracting that new object from Arr2 and assigning that object to a constant?
This is my best effort:
const newPlan
if (state.plans.length !== data.allPlansJson.edges.length) {
data.allPlansJson.edges.map(staticPlan => {
state.plans.map(planInState => {
planInState !== staticPlan && newPlan = staticPlan
})
})
}
Too add even more context:
I'm getting objects from the array data.allPlansJson.edges
and spreading them in my a database collection. I'm then getting all of those objects and putting them back into an array in my redux state.
This function is to detect when there is a new object added to the data.allPlansJson.edges
array and execute a redux action that posts this new object to my database collection.