TS-Scribe - v0.6.2
    Preparing search index...

    Function chunkArray

    • Chunks an array into smaller arrays of a specified size.

      This function splits a large array into smaller sub-arrays, each containing up to the specified number of elements. If the original array can't be evenly divided, the last chunk will contain the remaining elements.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to chunk.

      • size: number

        The size of each chunk.

      Returns T[][]

      An array of smaller arrays, each containing up to the specified size.

      const arr = [1, 2, 3, 4, 5, 6];
      const chunked = chunkArray(arr, 2);
      console.log(chunked); // [[1, 2], [3, 4], [5, 6]]