1、遍历数组,获取最大值
<script>
//定义一个函数 名叫getMax
//定义一个临时数组 名字叫tempArr
function getMax(tempArr){
//typeof 获取变量的数据类型
if(typeof tempArr !='object'){
console.error('数据类型不正确 必须是数组')
return;
}
//.length 获取数组的元素个数
if (tempArr.length==0){
console.error('数组不能为空')
return ('数组不能为空');
}
//max存放的是数组的最大值
let max=tempArr[0]
for(let i=1;i<tempArr.length