0

Is there a shorthand for the following?

startsWith !== '' || contains !== '' || endsWith !== ''

I am looking for something more clean but not the overkill

1 Answers1

4

Assuming that they are variables, you could create an array from startsWith, contains and endsWith and then check the array contains an empty string like below:

const array = [startsWith, contains, endsWith];

if (!array.includes('')) {
  ...
}
Tom
  • 1,158
  • 6
  • 19
  • Could also use `.filter(Boolean)` if you want a list of the values that arent empty strings – ButchMonkey Oct 22 '21 at 10:37
  • 1
    True, but the conditions we start with are explicitly a "not equal to an empty string", rather than a truthy check – Tom Oct 22 '21 at 11:05