Math.max() 및 sort() 함수를 사용하여 배열의 최대값을 찾을 수 있습니다.
1) Math.max()
Math.max() 함수는 일반적으로 배열의 모든 요소를 가져와 최대값을 얻기 위해 모든 값을 면밀히 조사합니다. 그 방법론은 아래 예제에서 설명합니다.
예시
<html>
<body>
<script>
function maximum(value) {
if (toString.call(value) !== "[object Array]")
return false;
return Math.max.apply(null, value);
}
document.write(maximum([6,39,55,1,44]));
</script>
</body>
</html> 출력
55.
2) 정렬()
정렬 및 비교 기능을 사용하여 배열의 요소를 내림차순 또는 오름차순으로 정렬할 수 있으며 나중에 length 속성을 사용하여 필요한 값을 찾을 수 있습니다.
예
<html>
<body>
<input type ="button" onclick="myFunction()" value = "clickme">
<p id="max"></p>
<script>
var numbers = [6,39,55,1,44];
document.getElementById("max").innerHTML = numbers;
function myFunction() {
numbers.sort(function(a, b){return a - b});
document.getElementById("max").innerHTML = numbers;
document.write(numbers[numbers.length-1]);
}
</script>
</body>
</html> 위의 프로그램에서 출력은 다음 이미지와 같이 표시됩니다.

출력
나중에 위의 click me 버튼을 클릭하면 최대값이 다음과 같이 표시됩니다.
55