Let's discuss an interesting way to work with JavaScript arrays. Consider the array below:
const allRows = [
{id: 1, name: Name 1},
{id: 2, name: Name 1},
{id: 3, name: Name 1},
{id: 4, name: Name 1},
{id: 5, name: Name 1},
{id: 6, name: Name 1},
{id: 7, name: Name 1},
{id: 8, name: Name 1},
{id: 9, name: Name 1},
{id: 10, name: Name 1},
{id: 11, name: Name 1},
{id: 12, name: Name 1},
{id: 13, name: Name 1},
{id: 14, name: Name 1},
{id: 15, name: Name 1},
{id: 16, name: Name 1},
{id: 17, name: Name 1},
{id: 18, name: Name 1},
{id: 19, name: Name 1},
{id: 20, name: Name 1},
{id: 21, name: Name 1},
{id: 22, name: Name 1},
{id: 23, name: Name 1},
{id: 24, name: Name 1},
{id: 25, name: Name 1},
{id: 26, name: Name 1},
{id: 27, name: Name 1},
{id: 28, name: Name 1},
{id: 29, name: Name 1},
{id: 30, name: Name 1},
];
// We want to rearrange the above array into the following paginated structure:
let rowsPaginated = [
[
{id: 1, name: Name 1},
{id: 2, name: Name 1},
{id: 3, name: Name 1},
{id: 4, name: Name 1},
{id: 5, name: Name 1},
{id: 6, name: Name 1},
{id: 7, name: Name 1},
{id: 8, name: Name 1},
{id: 9, name: Name 1},
{id: 10, name: Name 1}
],
[
{id: 11, name: Name 1},
{id: 12, name: Name 1},
{id: 13, name: Name 1},
{id: 14, name: Name 1},
{id: 15, name: Name 1},
{id: 16, name: Name 1},
{id: 17, name: Name 1},
{id: 18, name: Name 1},
{id: 19, name: Name 1},
{id: 20, name: Name 1}
],
[
{id: 21, name: Name 1},
{id: 22, name: Name 1},
{id: 23, name: Name 1},
{id: 24, name: Name 1},
{id: 25, name: Name 1},
{id: 26, name: Name 1},
{id: 27, name: Name 1},
{id: 28, name: Name 1},
{id: 29, name: Name 1},
{id: 30, name: Name 1}
]
];
I am considering a simple loop to convert the array, but I am open to other suggestions. Feel free to share your thoughts on the best approach to achieve this pagination.