I want to add an object and delete two objects in a function
const old1 = [
{item: "apple", number: 13}
]
const old2 = [
{item: "apple", number: 13},
{item: "banana", number: 11},
{item: "orange", number: 13}
]
First, I want to add an object in the array
const add = {item: "pear", number: 3}
Then I want to check if the array has these elements, if yes, then remove them. Here I want to remove anything "banana" and "orange"
const new2 =[
{item: "pear", number: 3},
{item: "apple", number: 13}
]
I tried old1.unshift to add an element. I also tried old2.splice(0,2) to remove elements but it is based of the index order. I should check the item property and remove the relative one.