I'm working on a project where I've got 2 object arrays and the following are the various cases the data can be in.
// Case 1
var arr1=[{id:1,quantity:10}]
var arr2=[{id:1,quantity:10},{id:2,quantity:20}]
// Case 2
var arr1=[]
var arr2=[{id:1,quantity:10},{id:2,quantity:20}]
// Case 3
var arr1=[{id:1,quantity:12}]
var arr2=[{id:1,quantity:10},{id:2,quantity:20}]
// Case 4
var arr1=[{id:1,quantity:10},{id:1,quantity:20}]
var arr2=[{id:1,quantity:10}]
So, the array1 might be empty, might have one of the objects from array2 or both the objects of array2 with a different quantity value.
I'd like to update the main array or arr1 based on arr2 but don't want to completely swipe arr1 with arr2 with arr1=arr2 kind of solution. arr1 should update quantity based on arr2 and add or remove based on the same thing.
arr1 = arr2?