I would like to create a two-dimensional array based on targetItems
with the number of numbers in splitNumber
and output it as follows.
const targetItems = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const splitNumber = 2;
We are looking for the following results.
[[1, 2, 3, 4, 5], [6, 7, 8, 9]];
Is there a good way?
I was thinking of using Math.round, etc. to carry it out if it can't be done evenly. If the number of targetItems is 5 and the splitNumber is 2
[[1,2,3], [4,5]]
If the number of targetItems is 17 and the splitNumber is 2
[[1,2,3,4,5,6,7,8,9], [10,11,12,13,14,15,16,17]]
If the number of targetItems is 5 and the splitNumber is 3
[[1,2], [3,4], [5]]