I have a code like this:
if (action == \'John\' || action == \'John Beckham\' || action == \'Henry John\'){
alert(\'true!\');
}
How do I m
In addition of indexOf
, you can also use conditional operator in Javascript.
names = ['John' ,
'John Beckham',
'John Henry' ,
'Giggs John' ,
'Scholes John',
'John Messi'
];
names.indexOf(action) != -1? alert('True') : alert ('False');
And you want to do more then simple statement do like:
names.indexOf(action) != -1? doSomethingOnTrue() : doSomethingOnFalse();