TS-Scribe - v1.2.0
    Preparing search index...

    Function arrayChunk

    • 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. Must be a positive, finite integer.

      Returns T[][]

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

      If size is not a positive, safe integer.

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