I have a unique challenge involving two arrays of objects that I need to merge while excluding any duplicates. Specifically, if an object with the key apple: 222
already exists in the first array, it should be excluded from the second array.
Please see below for the initial arrays:
var arr1 = [
{apple: 111, tomato: 55},
{apple: 222, tomato: 55}
]
var arr2 = [
{apple: 222, tomato: 55},
{apple: 333, tomato: 55}
]
The desired output should look like this:
var res = [
{apple: 111, tomato: 55},
{apple: 222, tomato: 55},
{apple: 333, tomato: 55}
]
Can you guide me on how I could achieve this using JavaScript?