DarioN1
DarioN1

Reputation: 2552

Angular - Filter array based on two property values

I'm having some problem in deleting the array items based on two property values..

If we compare to classic Sql delete command, What I have to do is something like this:

DELETE oImages WHERE idOffertRow = 1 and idProductImage = 2

I don't know how to convert this sql example command in typescript.

This is that I'm ttrying to do but it doesn't work:

this.oImages = this.oImages.filter(function (obj) {
          return obj.idOffertRow !== oRow.idOffertRow && obj.idProductImage !== i.idProductImage;
        });

Thanks to support

Upvotes: 0

Views: 544

Answers (1)

user4676340
user4676340

Reputation:

this.oImages = this.oImages.filter(obj => idOffertRow !== 1 || idProductImage !== 2);

Filter is about keeping, not deleting. So invert your condition. With De Morgan's law, it gives

A . B ---> !A + !B

Upvotes: 1

Related Questions