Javascript: Shorter a if ( … or …) condition

  • A+
if (args.join(" ").toLowerCase() === "are you" || args.join(" ").toLowerCase() === "are you doing") 

As you can see, I am using two very similar lines with an or case. Is there a shorter way to do this ?


["are you", "are you doing"].includes(args.join(" ").toLowerCase()) 

The benefits of this solution is that args.join(" ").toLowerCase() is only executed once and that it's non-verbose while still being expressive and easily understandable.
It's also easily scalable. If you have more strings you want to validate against, just add those strings to the array.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: