Switch Case To/Between
问题 Is there a way in Javascript to compare one integer with another through switch case structures without using if statements? E.g. switch(integer) { case 1 to 10: break; case 11 to 20: break; case 21 to 30: break; } 回答1: 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; } 回答2: There is a way, yes. I'm pretty sure I'd use an if/else structure in my