@sensimods/utility-lab
    Preparing search index...

    Function chunk

    • Splits an array into groups of a specified size. If the array can't be split evenly, the final chunk will contain the remaining elements.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        The array to be chunked.

      • size: number

        The size of each chunk (must be a positive integer).

      Returns T[][]

      An array of chunks, where each chunk is an array of elements.

      chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]