var arr = [1,2,3,4,5,6,7,8]; let size = 3; for(let i = 0; i < Math.ceil(arr.length / size); i++) { let start = i * size; let end = start + size; let subArr = arr.slice(start, end); console.log(subArr); } console.log(0%2); console.log(1%2); console.log(2%2); console.log(3%2);