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...
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...
Make an array and use indexOf
:
['NEBC', 'station:|slot:', 'slot:', 'believe'].indexOf(breadCrumbArr[x]) === -1
You could use a switch
statement:
switch(inputString){
case "ignoreme1":
case "ignoreme2":
case "ignoreme3":
break;
default:
//Do your stuff
break;
}
In addition to Blender's answer: if you want to go cross browser, you could also use an object instead of an array:
var words = {
'NEBC': true,
'station:|slot:': true,
'slot:': true,
'believe': true
};
if (!words[breadCrumbArr[x]]){
//do stuff
}
It's also faster but it's also definitly uglier since you have to assign a value (in this case true
) to every string that is used as property name.