Javascript If statement, looking through an array

后端 未结 3 554
攒了一身酷
攒了一身酷 2021-02-08 22:54

Mind has gone blank this afternoon and can\'t for the life of me figure out the right way to do this:

if(i!=\"3\" && i!=\"4\" && i!=\"5\" &&a         


        
3条回答
  •  深忆病人
    2021-02-08 23:38

    This solution is cross-browser:

    var valid = true;
    var cantbe = [3, 4, 5]; // Fill in all your values
    for (var j in cantbe)
        if (typeof cantbe[j] === "number" && i == cantbe[j]){
            valid = false;
            break;
        }
    

    valid will be true if i isn't a 'bad' value, false otherwise.

提交回复
热议问题