@pengzhanbo/utils - v3.7.3
    Preparing search index...

    Function chunk

    • Split array into chunks

      将数组拆分成块

      Type Parameters

      • T

        The type of elements in the array / 数组元素的类型

      Parameters

      • input: readonly T[]

        The array to be chunked. 要分块的数组

      • size: number = 1

        The size of each chunk. Defaults to 1. Floats are truncated via parseInt. If the result is not a positive integer, defaults to 1. 每个块的大小,默认为1。浮点数通过 parseInt 取整。如果结果不是正整数,则默认为 1。

      Returns T[][]

      A new array of chunks. 分块后的新数组

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