I have an array of objects and I want to check whether a given object is present in the array and if yes,I want to delete that,If not I have to add it to the array.
I am doing this:
var arr=[
{
name: "Jack",
type: "Jill",
},
{
name: "Heer",
type: "Ranjha",
},
{
name: "laila",
type: "Majnu",
};
]
var tosearch = {
name: "Jack",
type: "Jill",
};
if(arr.includes(tosearch))
{
//I want to delete it from the arr.
}
else
arr.push(tosearch)
How can I achieve the above implementation?
Thanks