Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a better way of testing if a string doesn't equal a bunch of stuff? [duplicate]

Tags:

javascript

right now I have:

if (breadCrumbArr[x] !== 'NEBC' && breadCrumbArr[x] !== 'station:|slot:' &&  breadCrumbArr[x] !== 'slot:' &&  breadCrumbArr[x] !== 'believe') {
    // more code
}

But I think this could be done better...

like image 777
sherlock Avatar asked Aug 05 '13 20:08

sherlock


2 Answers

Make an array and use indexOf:

['NEBC', 'station:|slot:', 'slot:', 'believe'].indexOf(breadCrumbArr[x]) === -1
like image 61
Blender Avatar answered Nov 15 '22 19:11

Blender


You could use a switch statement:

switch(inputString){
  case "ignoreme1":
  case "ignoreme2":
  case "ignoreme3":
    break;
  default: 
    //Do your stuff
    break;
}
like image 20
Xynariz Avatar answered Nov 15 '22 21:11

Xynariz