var arr = [] for (var i = 1; i <= 30; i++) { arr.push(2 * i) } console.log(arr) var newArr = [] var add = 0 for (var j = 0; j < arr.length; j++) { add += arr[j]; if ((j + 1) % 5 === 0) { newArr.push(add / 5) add = 0 } } console.log(newArr)