Filter by multiple options - also only if not empty
Is this what you're after?

criteria.filter({ _id, criteriaType } =&gt; (
    (!participantType || participantType === criteriaType)
    &amp;&amp;
    (!participantCriteriaId || participantCriteriaId === _id)
));


If participantType is empty, it will be coerced to true by the negation, which short-circuits the || operator, so it won't check the right-hand side of the condition. Same for participantCriteriaId.

Note: This type of condition is a common pattern in boolean logic. Generally speaking, conditions that can be phrased as:


  If A is true, then check if B is true; otherwise, ignore this condition


Can be transcribed as:


  (not A) or B


Which in code is:

!a || b


In your case, the condition is "if the search filter is populated, then check for equality, otherwise ignore", which is transcribed as !filter || property === filter.