I want to remove 3rd object from an array in which the color is red. I want to remove it using the index as some objects may not have an _id attribute and other attributes are not unique among them.
[
{ color: "BLUE"
imageURL: "/uploads/image-1639632524718.png"
inStock: 4
_id: "61b9bff23b027548ed2f737e"
},
{ color: "green"
imageURL: "/uploads/image-1639561204805.png"
inStock: 6
_id: "61ba098f3b027548ed2f737f"
},
{ color: "Red"
imageURL: "/uploads/image-1639647424471.png"
inStock: 6
},
{ color: "Star Light"
imageURL: "/uploads/image-1639650244179.png"
inStock: 60
}
]
After removing the object array will look like.
[
{ color: "BLUE"
imageURL: "/uploads/image-1639632524718.png"
inStock: 4
_id: "61b9bff23b027548ed2f737e"
},
{ color: "green"
imageURL: "/uploads/image-1639561204805.png"
inStock: 6
_id: "61ba098f3b027548ed2f737f"
},
{ color: "Star Light"
imageURL: "/uploads/image-1639650244179.png"
inStock: 60
}
]
How can I do this?