在 Javascript 中有没有一种方法可以在不使用 if 语句的情况下通过 switch case 结构将一个整数与另一个整数进行比较?
Is there a way in Javascript to compare one integer with another through switch case structures without using if statements?
例如
switch(integer) {
case 1 to 10:
break;
case 11 to 20:
break;
case 21 to 30:
break;
}
你可以做一些数学运算.
You can do some math manipulations.
switch(Math.ceil(integer/10)) {
case 1: // Integer is between 1-10
break;
case 2: // Integer is between 11-20
break;
case 3: // Integer is between 21-30
break;
}
这篇关于切换案例到/之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!