Copy the code code as follows:
<html>
<head>
<title>Getting the maximum value of an array</title>
<script>
//define array
var arr = [1,4,3,9,5,0,-1,7,22];
//The subscript of the maximum value is first assumed to be the subscript of the first element
var index = 0;
for(var x = 0; x < arr.length; x++){
if(arr[index] < arr[x]){
index = x;
}
}
document.write("Index is" + index + "in" + arr[index] + "maximum");
</script>
</head>
<body>
<div id="time"></div>
</body>
</html>