[英]How to write if else statement with a value with multiple value set?
So for my 'f' value, it has from 1-15.所以对于我的“f”值,它有 1-15。 How do I write my if-else statement if I want if f value == 1,6,7,8,9,10,12 it does something if-else f value == 2,3,4,5,13,14,15 do something else?
如果我想要 if f value == 1,6,7,8,9,10,12 它做了一些 if-else f value == 2,3,4,5,13,我该如何写我的 if-else 语句, 14,15做点别的?
if(a == "BLK A ", d == "BLK D ", e == "5", f == "1 "){
// do something
}
else if (f =="6"){
// do something
}
You could take Array#includes
with the wanted values.您可以将
Array#includes
与所需的值一起使用。
It is necessary to take the same type of the value, like string or numbers.必须采用相同类型的值,如字符串或数字。 If different types, you need to normalize the value to all numbers or strings.
如果类型不同,则需要将值归一化为所有数字或字符串。
if (['1', '6', '7', '8', '9', '10', '12'].includes(f)) { }
you can use the parseInt()
function:您可以使用
parseInt()
函数:
var valueOfF = parseInt(f)
if(valueOfF >=1 && valueOfF <=10){
//doSomething
}
else if(valueOfF >=11 && valueOfF <= 15){
//doSomething
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.