javascript checking multiple conditions in if statement - javascript

I have an if statement which checks multiple conditions. I would like it to skip the conditional statement if at least one thing returns false. I can see that it is currently picking up the conditional statement if at least one thing is true.
if((api != 'abosp') || (api !='sersp') || (api !='volsp') || (api !='consp') || (api !='givsp') || (api !='blosp')){
console.log("api: " + api );
api = 'cussp'
}
What would be the correct way to implement this kind of logic?
Currently if api == 'abosp' it will still pass into the conditional statement instead of skipping it.

You should change your || for and operator: &&. Still, a more "clean" method would be:
banned = ["abosp", "sersp", "volsp", "consp", "givsp", "blosp"]
if(banned.indexOf(api) == -1){ // if api is not in list
console.log("api: " + api );
api = 'cussp'
}

Actually your if can't be evaluated to true since api can't be all the values you check. I guess you need an and (&&) instead of an or (||):
if ((api != 'abosp') && (api !='sersp') && ...
In this case, you can use an associative array to have more succinct code:
d = {abosp: 1, sersp: 1, volsp: 1, consp: 1, givsp: 1, blosp: 1};
if (!d[api]) api = 'cussp';

I think you are looking for && rather than ||.
This will skip the conditional statement if any of the individual comparisions return false.

Related

reactjs OR condition breaks in the second comparison

I'm trying to add different Id to a component based on a certain value.
My approach is like below
id={activePage === ('dashboard' || 'evc_detail')? 'bg_gradient':'bg_normal'}
In this scenario if the activePage is equal to dashboard the correct id is added but it does not register if activePage is equal to evc_detail. Is the way i'm using this condition wrong and how can i solve this?
If you want to multiple comparisons you'll need to state them manually:
(activePage === 'dashboard' || activePage === 'evc_detail') ? 'bg_gradient' : 'bg_normal'
Another option is create an array of items (or a Set), and use Array.includes() (or Set.has) to check if an item is in the group:
const gradientPages = ['dashboard', 'activePage']
gradientPages.includes(activePage) ? 'bg_gradient' : 'bg_normal'
Your original expression activePage === ('dashboard' || 'evc_detail')? 'bg_gradient':'bg_normal' doesn't work if the activePage is not 'dashbarod' because of the way it's evaluated:
'dashboard' || 'evc_detail' is evaluated, since 'dashboard' is a truthy expression, the result is always dashboard.
'dashboard' is compared with activePage. If activePage is 'dashboard' the result is true, if not it's false.

If-statement not filtering out undefined

I am trying to cleanse a dataset, but my if statement appears not to work.
The first part, x.sites.length>0, seems to work by itself.
The second part, (x !== undefined), doesn't seem to register at all. In my return Array, some of the undefineds are still there. I have tried various different ways of writing (x !== undefined), but none of them seem to work for me.
Any thoughts?
export function clenseData(dataset){
let cleansedSet = dataset.map(x=>{
if(x.sites.length>0 && (x !== undefined))
{return x;}//doesn't work.
})
console.log(cleansedSet);
debugger;
return cleansedSet;
}
Here is the JSON String for one of the inputs: {"data":{"success":true,"data":[{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Roxanne Modafferi","Valentina Shevchenko"],"commence_time":1555754400,"home_team":"Roxanne Modafferi","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[3.35,1.3]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[3.8,1.27]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[3.35,1.3]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[3.75,1.28]}},{"site_key":"williamhill","site_nice":"William Hill","last_update":1555332878,"odds":{"h2h":[3.25,1.33]}}],"sites_count":5},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Marcin Tybura","Shamil Abdurakhimov"],"commence_time":1555754400,"home_team":"Marcin Tybura","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.57,2.3]}},{"site_key":"matchbook","site_nice":"Matchbook","last_update":1555333223,"odds":{"h2h":[1.63,2.39]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.55,2.4]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.57,2.3]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[1.6,2.31]}},{"site_key":"williamhill","site_nice":"William Hill","last_update":1555332878,"odds":{"h2h":[1.53,2.38]}}],"sites_count":6},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Aleksei Oleinik","Alistair Overeem"],"commence_time":1555754400,"home_team":"Alistair Overeem","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.9,1.4]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.9,1.4]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[2.96,1.41]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.9,1.41]}},{"site_key":"williamhill","site_nice":"William Hill","last_update":1555332878,"odds":{"h2h":[2.9,1.4]}}],"sites_count":5},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Keita Nakamura","Sultan Aliev"],"commence_time":1555754400,"home_team":"Sultan Aliev","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.8,1.95]}},{"site_key":"matchbook","site_nice":"Matchbook","last_update":1555333223,"odds":{"h2h":[1.85,1.97]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.81,2]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.8,1.95]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[1.86,1.92]}},{"site_key":"williamhill","site_nice":"William Hill","last_update":1555332878,"odds":{"h2h":[1.8,1.91]}}],"sites_count":6},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Alexander Volkov","Luis Henrique Da Silva"],"commence_time":1555786800,"home_team":"Luis Henrique Da Silva","sites":[{"site_key":"ladbrokes","site_nice":"Ladbrokes","last_update":1555333247,"odds":{"h2h":[1.74,2.05]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.66,2.23]}},{"site_key":"betfair","site_nice":"Betfair","last_update":1555332863,"odds":{"h2h":[1.66,2.18]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Marcin Tybura","Shamil Abdurakhimov"],"commence_time":1555790400,"home_team":"Shamil Abdurakhimov","sites":[{"site_key":"ladbrokes","site_nice":"Ladbrokes","last_update":1555333247,"odds":{"h2h":[1.55,2.4]}},{"site_key":"betfair","site_nice":"Betfair","last_update":1555332863,"odds":{"h2h":[1.53,2.48]}}],"sites_count":2},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Keita Nakamura","Sultan Aliev"],"commence_time":1555790400,"home_team":"Sultan Aliev","sites":[{"site_key":"ladbrokes","site_nice":"Ladbrokes","last_update":1555333247,"odds":{"h2h":[1.8,2]}},{"site_key":"betfair","site_nice":"Betfair","last_update":1555332863,"odds":{"h2h":[1.79,1.99]}}],"sites_count":2},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Roxanne Modafferi","Valentina Shevchenko"],"commence_time":1555790400,"home_team":"Roxanne Modafferi","sites":[{"site_key":"matchbook","site_nice":"Matchbook","last_update":1555333223,"odds":{"h2h":[3.78,1.3]}},{"site_key":"ladbrokes","site_nice":"Ladbrokes","last_update":1555333247,"odds":{"h2h":[3.7,1.27]}},{"site_key":"betfair","site_nice":"Betfair","last_update":1555332863,"odds":{"h2h":[3.45,1.28]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Aleksei Oleinik","Alistair Overeem"],"commence_time":1555801200,"home_team":"Aleksei Oleinik","sites":[{"site_key":"betfair","site_nice":"Betfair","last_update":1555332863,"odds":{"h2h":[3.05,1.45]}},{"site_key":"matchbook","site_nice":"Matchbook","last_update":1555333223,"odds":{"h2h":[2.95,1.42]}},{"site_key":"ladbrokes","site_nice":"Ladbrokes","last_update":1555333247,"odds":{"h2h":[3,1.39]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Alex Oliveira","Mike Perry"],"commence_time":1556406000,"home_team":"Mike Perry","sites":[],"sites_count":0},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Cory Sandhagen","John Lineker"],"commence_time":1556406000,"home_team":"Cory Sandhagen","sites":[{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.15,1.65]}},{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.15,1.65]}}],"sites_count":2},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jack Hermansson","Ronaldo Souza"],"commence_time":1556413200,"home_team":"Jack Hermansson","sites":[{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.15,1.7]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.25,1.62]}},{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.25,1.62]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Glover Teixeira","Ion Cutelaba"],"commence_time":1556413200,"home_team":"Glover Teixeira","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.2,1.62]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.24,1.65]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[2.31,1.63]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.2,1.62]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Court McGee","Dhiego Lima"],"commence_time":1556413200,"home_team":"Court McGee","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.62,2.2]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.6,2.33]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.62,2.2]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Andrei Arlovski","Leonardo Augusto Guimaraes"],"commence_time":1556413200,"home_team":"Andrei Arlovski","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.1,1.68]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.22,1.66]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.1,1.68]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jessica Penne","Jodie Esquibel"],"commence_time":1556413200,"home_team":"Jessica Penne","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.55,2.35]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.51,2.55]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.55,2.35]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jason Gonzalez","Jim Miller"],"commence_time":1556413200,"home_team":"Jim Miller","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.25,1.6]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.27,1.63]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.25,1.6]}}],"sites_count":3},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Alex Volkanovski","Jose Aldo"],"commence_time":1557622800,"home_team":"Jose Aldo","sites":[{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.05,1.72]}},{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.05,1.72]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.09,1.74]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[2.12,1.74]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jessica Andrade","Rose Namajunas"],"commence_time":1557626400,"home_team":"Rose Namajunas","sites":[{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.65,2.2]}},{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.65,2.2]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.71,2.13]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[1.7,2.18]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Alexander Gustafsson","Ashlee Evans Smith"],"commence_time":1559422800,"home_team":"Alexander Gustafsson","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.44,2.7]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.48,2.6]}}],"sites_count":2},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jessica Eye","Valentina Shevchenko"],"commence_time":1560045600,"home_team":"Valentina Shevchenko","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[6,1.12]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[6,1.12]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[6.25,1.12]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[8,1.08]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Henry Cejudo","Marlon Moraes"],"commence_time":1560049200,"home_team":"Henry Cejudo","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[2.1,1.72]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[2.1,1.72]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[2.12,1.74]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[2.09,1.74]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Amanda Nunes","Holly Holm"],"commence_time":1562464800,"home_team":"Amanda Nunes","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.3,3.45]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.3,3.45]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.3,3.5]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[1.31,3.52]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Jon Jones","Thiago Santos"],"commence_time":1562468400,"home_team":"Jon Jones","sites":[{"site_key":"unibet","site_nice":"Unibet","last_update":1555332974,"odds":{"h2h":[1.14,5.5]}},{"site_key":"sport888","site_nice":"888sport","last_update":1555332928,"odds":{"h2h":[1.14,5.5]}},{"site_key":"nordicbet","site_nice":"Nordic Bet","last_update":1555332998,"odds":{"h2h":[1.17,5]}},{"site_key":"marathonbet","site_nice":"Marathon Bet","last_update":1555332887,"odds":{"h2h":[1.16,5.4]}}],"sites_count":4},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Colby Covington","Kamaru Usman"],"commence_time":1562475600,"home_team":"Colby Covington","sites":[],"sites_count":0},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Dustin Poirier","Khabib Nurmagomedov"],"commence_time":1568523600,"home_team":"Dustin Poirier","sites":[],"sites_count":0},{"sport_key":"mma_mixed_martial_arts","sport_nice":"MMA","teams":["Israel Adesanya","Robert Whittaker"],"commence_time":1569697200,"home_team":"Israel Adesanya","sites":[],"sites_count":0}]},"status":200,"statusText":"","headers":{"x-requests-remaining":"24","content-type":"application/json;charset=utf-8","x-requests-used":"126"},"config":{"transformRequest":{},"transformResponse":{},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"headers":{"Accept":"application/json, text/plain, */*"},"method":"get","url":"https://api.the-odds-api.com/v3/odds/?apiKey=b80b98e306cbe877f35c7db3804d2d72&sport=mma_mixed_martial_arts&region=uk&mkt=h2h"},"request":{}}
Are you trying to filter the data? if so you should be using filter function & not map. The map is used when you want to iterate over the data.
export function clenseData(dataset){
let cleansedSet = dataset.filter(x => {
if(x !== undefined && x.sites.length > 0) {
return true; // if you want to include it in the cleaned data
}
})
return cleansedSet;
}
The every() method tests whether all elements in the array pass the test implemented by the provided function:
dataset.every((x) => x !== undefined && x.sites.length> 0);

Want to shorten my if statement using Lodash

I am looking to optimize the below piece of code using Lodash. I have looked for solutions online, but could not find anything relevant. Can someone please help?
if (isPage && isPageType === constants.keys.isDisclosureSubmitted) {
if (form && form.application && typeof form.application.disclosureAccepted !== 'undefined' && form.application.disclosureAccepted !== null && !form.application.disclosureAccepted) {
return $q.when(response.data.content);
}
}
if (isPage && isPageType === constants.keys.isDisclosureSubmitted) {
const discAcc = _.get(form, ['application', 'disclosureAccepted'], true);
if (!_.isNil(discAcc) && !disAcc) {
return $q.when(response.data.content);
}
}
Basically, with _.get, you don't have to worry about checking a property of undefined, since it will just return undefined in that scenario rather than throw an error. _.isNil check is the value is both null or undefined, and then you want to make sure the value is still falsey.
I mean, I'm not sure if lodash "optimizes" in this case, since these function calls will actually slow it down, but it is slightly more readable. Like the comments, I'm not sure exactly why you need to be so specific; you could just use _.get(form, ['application', 'disclosureAccepted']) == false, thought I sway against using unstrict equivalence.

Parse.Query and-combination issue

In cloud code, I made a query using this sort of code:
theMainQuery = new Parse.Query("myClass");
theMainQuery.equalTo("fieldOne", "champion");
theSubQuery = new Parse.Query("myClass");
theSubQuery.equalTo("fieldTwo", "USA");
the2ndSubQuery = new Parse.Query("myClass");
the2ndSubQuery.equalTo("fieldTwo", "BRASIL");
theSubQuery = Parse.Query.or(theSubQuery,the2ndSubQuery);
theMainQuery = Parse.Query.and(theMainQuery,theSubQuery);
In other words I want a query based on this condition:
((fieldOne equals "champion") and ((fieldTwo equals "USA") or (fieldTwo equals "BRASIL")))
In usual C style writing I want to select records matching:
((fieldOne == "champion") && ((fieldTwo == "USA") || (fieldTwo == "BRASIL")))
The problem is that it does not work, I suppose my Parse.Query.and is wrong. Then how can I get the result I want?
Of course, I would be happy to avoid reformulating the query in this long format:
(((fieldOne == "champion") && (fieldTwo == "USA")) || ((fieldOne == "champion") && (fieldTwo == "BRASIL")))
Okay so what you want to do can be done within one Query object.
I feel what your looking for is 'containedIn'... So you specify the key 'fieldTwo' and pass in an array of values to 'or' with.
So heres what I think it should look like, I implemented this in Objective-C but not javascript. but heres my javascript version
var query = new Parse.Query('myclass');
query.equalTo('fieldOne', 'champion');
query.containedIn('fieldTwo', ['USA', 'Brazil']);
query.find();
I hope this was what your looking for... By the way, I was able to find this in the docs, https://parse.com/docs/js_guide#queries. There docs are very helpful but sometimes doesn't help me :P

conditional if for many values, better way

Is there a better way to deal with checking multiple values. It starts to get really busy when I have more than 3 choices.
if (myval=='something' || myval=='other' || myval=='third') {
}
PHP has a function called in_array() that's used like this:
in_array($myval, array('something', 'other', 'third'))
Is there something like it in js or jquery?
Jquery.inArray()
Besides $.inArray, you could use Object notation:
if (myval in {'something':1, 'other':1, 'third':1}) {
...
or
if (({'something':1, 'other':1, 'third':1}).hasOwnProperty(myval)) {
....
(Note that the 1st code won't work if the client side has modified Object.prototype.)
You can avoid iterating over the array by using some kind of a hash map:
var values = {
'something': true,
'other': true,
'third': true
};
if(values[myVal]) {
}
Does also work without jQuery ;)
a clean solution taken from the 10+ JAVASCRIPT SHORTHAND CODING TECHNIQUES:
longhand
if (myval === 'something' || myval === 'other' || myval === 'third') {
alert('hey-O');
}
shorthand
if(['something', 'other', 'third'].indexOf(myvar) !== -1) alert('hey-O');

Categories