Categories
Splits an array into chunks of a specified size.
Contributed by @itsbrunodev
function chunkArray(array, size) { return Array.from({ length: Math.ceil(array.length / size) }, (_, i) => array.slice(i * size, i * size + size) ); }
const numbers = [1, 2, 3, 4, 5, 6, 7]; chunkArray(numbers, 3); // [[1, 2, 3], [4, 5, 6], [7]]