You can use Math.max and apply
if (5 > Math.max.apply(Math, array)) {
// do something
}
Update: To explain as it works. It's described in the docs I linked but I will try to be more clear here:
Math.max returns the largest of zero or more numbers, so:
Math.max(1, 2, 3, 4) // returns 4
apply calls a function with a given 'this' value (the first argument) and arguments provided as an array (the second). so:
function sum(a, b) {
return a + b;
}
console.log(sum.apply(window, [2, 3])); // 5
Therefore, if you have an array of integers and you want to get the max, you can combine them to have:
console.log(Math.max.apply(Math, [1, 2, 3, 4])); // 4
Because it's exactly like have:
console.log(Math.max(1, 2, 3, 4));
The difference is you pass an array instead.
Hope it's more clear now!