js2---60,每五个数取平均值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr=new Array(30);
        var num=0;
        for(var i=0;i<arr.length;i++){ 
            num+=2;
            // console.log(num);
            arr[i]=num
        }
        console.log(arr);
        var newArr=[];
        var sum=0;
        for(var j=0;j<arr.length;j++){
            // console.log(arr[j]);
            // sum+=arr[j];
            if((j+1)%5===0){
                newArr.push(sum/5);
                sum=0;
            }
        }
        console.log(newArr);
    </script>
</body>
</html>
posted @ 2020-11-07 10:55  无敌臭弟弟  阅读(217)  评论(0编辑  收藏  举报