Reduce multiple ORs in IF statement in JavaScript

前端 未结 8 550
借酒劲吻你
借酒劲吻你 2020-12-07 02:17

Is there a simpler way to rewrite the following condition in JavaScript?

if ((x == 1) || (x == 3) || (x == 4) || (x == 17) || (x == 80)) {...}
8条回答
  •  [愿得一人]
    2020-12-07 02:39

    You can optimize your own example and get rid of a few characters, making it easier on the eyes..:

    if (x == 1 || x == 3 || x == 4 || x == 17 || x == 80) { ... }
    

提交回复
热议问题