Function splitIntoChunks

  • Splits an array into smaller chunks of a specified size.

    This function takes a source array and divides it into chunks of the given size. Each chunk is represented as an object with a unique key and an array of items.

    Example

    const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    const chunks = splitIntoChunks(data, 3);
    // Output: [{ key: 0, items: [1, 2, 3] }, { key: 1, items: [4, 5, 6] }, { key: 2, items: [7, 8, 9] }]

    Type Parameters

    • T

    Parameters

    • source: T[]

      The source array to be split into chunks.

    • chunkSize: number

      The size of each chunk.

    Returns TChunk<T>[]