Usually we will use the first method, but there is a very simple method: Math.max.apply(null, arr)
const arr = [16,2,4,32,6,7];
function max(arr) {
let maxVal = arr[0];
for(let i of arr) {
maxVal = maxVal>i?maxVal:i;
}
return maxVal;
}
console.log(max(arr));// 32
console.log( Math.max.apply(null,arr) ); // 32