I have two different arrays as shown below:
const firstArray = [{name: "1"}, {name: "2"}, {name: "3"}, {name: "4"}, {name: "4"}];
const secondArray = [{name: "1"}, {name: "5"}, {name: "3"}, {name: "4"}, {name: "4"}, {name: "4"}, {name: "1"}, {name: "1"}, {name: "2"}];
The desired output is:
[{name: "1"}, {name: "2"}, {name: "3"}, {name: "4"}, {name: "4"}, {name: "5"}, {name: "4"}, {name: "1"}, {name: "1"}];
The resulting array should contain all elements from the first array and any unique elements from the second array that are not already present in the first array
I attempted to use _.unionBy
_.unionBy(firstArray, secondArray, 'name')
However, this only returns an array with unique 'name' values
Is there a way to achieve this using lodash?