@jossmac/lil-libs
    Preparing search index...

    Function chunk

    • Splits an array into consecutive chunks of at most size elements.

      The final chunk may be smaller when the array length is not evenly divisible.

      • T
      • arr: T[]

        Array to split into consecutive segments.

      • size: number

        Maximum number of elements per chunk; the final chunk may contain fewer.

      Consecutive slices of arr, each up to size elements long. Returns [] when arr is empty.

      chunk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]
      chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
      chunk([1, 2, 3], 10); // [[1, 2, 3]] (size larger than array)
      chunk([], 2); // []