Function chunk
- chunk<T>(array, size): T[][]
Type Parameters
Parameters
- array: readonly T[]
The array to split into chunks.
- size: number
The size of the chunks. This must be a positive integer.
Returns T[][]
An array of chunks of the given size.
Example: Basic usage
import { chunk } from "@std/collections/chunk";
import { assertEquals } from "@std/assert";
const words = [
"lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consetetur",
"sadipscing",
];
const chunks = chunk(words, 3);
assertEquals(
chunks,
[
["lorem", "ipsum", "dolor"],
["sit", "amet", "consetetur"],
["sadipscing"],
],
);- array: readonly T[]
Splits the given array into chunks of the given size and returns them.