Hamza L. Hamza L. - 1 month ago 4x
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