javascript中数组中求最大值

来源:互联网 发布:js http 状态码 编辑:程序博客网 时间:2024/05/31 19:38
<html><head><title>数组的最大值的获取</title><script>//定义数组var arr = [1,4,3,9,5,0,-1,7,22];//最大值的下标,先假定为第一个元素的下标var index = 0;for(var x = 0; x < arr.length; x++){if(arr[index] < arr[x]){index = x;}}document.write("索引为" + index + "中的" + arr[index] + "最大");</script></head><body><div id="time"></div></body></html>

0 0