假设我有变量"a,b,c,d,e,f",我想检查它们中的任何一个是否有大于10的值.
var myvars = [a,b,c,d,e,f]
if((Any value in these variables) > 10) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
我搜索了但是我找不到比逐个检查它们更短的方法.任何想法都会让我开心.
var numbers = [1, 5, 7, 3, 9];
var max = Math.max.apply(Math, numbers);
if(max > 10) {
// contains a number that is greater than 10
}
Run Code Online (Sandbox Code Playgroud)
或简短形式:
var numbers = [1, 5, 7, 3, 9];
if(Math.max.apply(Math, numbers) > 10) {
// contains a number that is greater than 10
}
Run Code Online (Sandbox Code Playgroud)