I am currently working with two arrays of objects. One array retrieves data from an API to display in the application, while the other array fetches data from localStorage, which includes modifications made to the original data stored in the first array. My goal is to combine these two arrays, but I need to ensure that there are no duplicate objects to prevent redundant rendering.
Here's an example of the desired outcome:
data1 = [
{customer: {
purchased: false,
id: 1
}},
{customer: {
purchased: false,
id: 2
}}
]
data2 = [
{customer: {
purchased: true,
id: 1
}}
]
data3 = data1.concat(data2)
result:
data3 = [
{customer: {
purchased: true,
id: 1
}},
{customer: {
purchased: false,
id: 2
}}
]
I have been struggling to find an effective way to compare the two arrays. Despite brainstorming various approaches, I have been unsuccessful in my attempts.