• Internal

    Returns a new generator that yields elements that are arrays of size n grouped from the input iterable, by taking n elements at a time.

    The last group may have less than n elements.

    Type Parameters

    • T

      The element type of the input iterable

    Parameters

    • iterable: Iterable<T>

      The input iterable

    • n: number

      The size of the groups

      Returns a new generator yielding arrays of size n grouped from the input iterable, of type T[].

    Returns Generator<T[], void, undefined>

    Example

    const input = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    const result = [...chunk(input, 3)];
    console.log(result); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Generated using TypeDoc