I need to split an Array into multiple arrays one by one, for example, if I have an array
const input = [1, 2, 3, 4, 5, 6, 7, 8, 9];
And the number of multiple arrays
would be 3
, the output should be
const arraysNumber = 3;
const result = [[1,4,7], [2,5,8], [3,6,9]];
if multiple arrays
= 2,
const arraysNumber = 2;
result = [[1,3,5,7,9], [2,4,6,8]];
if multiple arrays
= 4,
const arraysNumber = 4;
result = [[1,5,9], [2,6], [3,7], [4,8]];
I found only ways hot to split on chunks, like [[1,2,3], [4, 5, 6], [7, 8, 9]]
, but that’s not what I need
Would be grateful for any help!