I have two arrays, I want these two to be combined and duplicate items are not lit and only new items are added and I see the combined array in the console I also want to see the duplicate item in the list on the console I mean, I need two outputs, one to tell me what a duplicate is, and one to show me a new array of combinations of two arrays without duplicates. I wrote this code but it does not work properly Thanks for guiding me
Expected output:
newContact : [
{
"id": 1,
"name": "Oliver"
},
{
"id": 2,
"name": "Liam"
}
{
"id": 3,
"name": "James"
}
{
"id": 4,
"name": "Lucas"
}
]
duplicateContacts: Oliver
let array1 = [
{ id: 1, name: "Oliver" },
{ id: 2, name: "Liam" },
];
let array2 = [
{ id: 1, name: "Oliver" },
{ id: 3, name: "James" },
{ id: 4, name: "Lucas" },
];
let newContact = array1.filter((item) => item.id !== array2.id);
console.log("newContact :", newContact);
console.log("duplicateContacts:");