I'm trying to filter an object of array localcartArr to exclude any object that's included in the products array, but it returns the same localcartArr without excluding this object:
{ "productID": "5f6fd57f8b6f6b0017992443" }
Which exists in products array, it works only with === operator, but doesn't work with the not equal operation != or !==.
const products = [
{
"_id": "60242abc209cbd32d8e85ec8",
"productID": "5f6fd4f18b6f6b001799243f",
"quantity": 2
},
{
"_id": "60242b00209cbd32d8e85ec9",
"productID": "5f6fd57f8b6f6b0017992443",
"quantity": 1
}
]
let localcartArr = [
{
"productID": "5f6fd57f8b6f6b0017992443",
"quantity": 2
},
{
"productID": "5f6fd12a8b6f6b001799242f",
"quantity": 1
},
{
"productID": "5f7a5668a9baa50017d495e8",
"quantity": 1
}
]
let filterd = localcartArr.filter(local => {
return products.some(product => {
return local.productID !== product.productID
});
});