I have two arrays: productos
and prevProductos
, I'm filtering them to check if they have an object with the same properties and deleting them if it's true.
I want to check if they have the same id
, the same amount
and the same cost
, if the three of those properties are the same I want to delete that object but if one changes I need to keep it.
This line of code doesn't work because I changed the "amount" property so they're not equals but I get an empty object, how can I fix that?
example:
const productos = [{
prodId: 3,
amount: 30,
const:100
}];
const prevProductos = [{
prodId: 3,
amount: 20,
const:100
}]
let addedProducts = productos.filter( item =>
!prevProductos.some( obj =>
( obj.prodId === item.prodId
&& obj.amount === item.amount
&& obj.cost === item.cost
)
)
);
console.log(addedProducts)
//should show
[{
prodId: 3,
amount: 20,
const:100
}]
// currently getting
[]