[Solved] How to split array into three arrays by index? [closed]


You could take the remainfer of the index with three and address the dame group for every third element.

If necessary take destructuring assignment, like

[array0, array1, array2] = result;

const
    array = [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }],
    result = array.reduce((r, o, i) => ((r[i % 3] = r[i % 3] || []).push(o), r), []);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

solved How to split array into three arrays by index? [closed]