JavaScript求数组平均值
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title></title></head>&
·
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var arr = [10,20,30,56,89];
function avg(array) {//封装求平均值函数
var len = arr.length;
var sum = 0;
for(var i = 0;i<len;i++){
sum +=array[i];
}
return sum/len;
}
console.log(avg(arr));
</script>
</body>
</html>
更多推荐
已为社区贡献1条内容
所有评论(0)