Try .find with two conditions

Viewed 31

Good morning guys, I'm trying to do a .find with a double condition, but it wasn't working. Am I doing something wrong?

If my object has a different condition like discount@shipping (and in this case I don't want it to be assigned to the variable) it passes the validation.

let calculoDesconto = item.PriceTags.find((n => n.Name == "DISCOUNT@MARKETPLACE") || (n => n.Name === "discount@price"));

1 Answers

You're attempting to pass two functions to find, and find does not accept two functions. Even if it did, you would not pass them separated by an ||, and JavaScript cannot compose functions in this way.

You need to pass a single function that tests its input against both values:

n => n.Name == "DISCOUNT@MARKETPLACE" || n.Name == "discount@price"
Related