Hamza L. Hamza L. - 1 year ago 75
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


Answer Source
if (['Cancelled', 'Rejected', 'Delivered', 'Confirmed'].indexOf(a) == -1) {
  // do stuff here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download