Optimize OR in IF

前端 未结 7 808
不思量自难忘°
不思量自难忘° 2021-01-22 01:50

I have a code like this:

if (action == \'John\' || action == \'John Beckham\' || action == \'Henry John\'){
     alert(\'true!\');
}

How do I m

7条回答
  •  执笔经年
    2021-01-22 02:42

    Make an array as below.

    var newAry = array('a','b','c');
    

    Now just check it as below.

    $(function()
    {
        var newAry = Array('a','b','c');
        if($.inArray(action,newAry)){ alert(action); }
    });
    

提交回复
热议问题