I have an arrangement of 10 elements and I want to divide them from 2 into 2 elements.
let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
let res = [];
let parcial = [];
for (let i = 0; i < array.length; i++) {
parcial.push(array[i]);
if (i % 2 === 0) {
res.push(parcial);
parcial = [];
}
}
console.log(res);
The expected result is: [[1,2],[3,4],[5,6],[7,8],[9,0]]
, but what I get is
[
[1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]
]
How do I solve it?