Hamza L. Hamza L. - 6 months ago 26
Javascript Question

JavaScript - Shorthand of "Or" inside an if statement

Is there a shorthand for "Or" condition inside an if statement, I feel it's stupid to be repetitive, in the below case "a" variable is repetitive to check all the "Or" conditions:

if(a != 'Cancelled' || a != 'Rejected' || a != 'Delivered' || a != 'Confirmed'){

//execute something here


if (['Cancelled', 'Rejected', 'Delivered', 'Confirmed'].indexOf(a) == -1) {
  // do stuff here