Saltar al contenido principal

Function: useChunk()

useChunk<T>(array, size): T[][]

Defined in: src/core/services/utils.service.ts:33

Splits an array into chunks of the given size.

Type Parameters

T

T

Element type.

Parameters

array

T[]

The input array.

size

number

Number of elements per chunk (must be > 0).

Returns

T[][]

An array of chunks.

Throws

If size is less than or equal to 0.

Example

useChunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
useChunk(["a", "b", "c"], 1); // [["a"], ["b"], ["c"]]