• 数组分片

    类型参数

    • T
    • L extends number

    参数

    • arr: ArrayLike<T>
    • chunkLen: L

    返回 TupleM2N<T, 0, L>[]

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

    chunk([0, 1, 2, 3, 4, 5, 6], 10); // [[0, 1, 2, 3, 4, 5, 6]]
    chunk([0, 1, 2, 3, 4, 5, 6], 1); // [[0], [1], [2], [3], [4], [5], [6]]
    chunk([0, 1, 2, 3, 4, 5, 6], 0); // [0, 1, 2, 3, 4, 5, 6]
    chunk([0, 1, 2, 3, 4, 5, 6], -1); // [0, 1, 2, 3, 4, 5, 6]
    chunk([0, 1, 2, 3, 4, 5, 6], 3); // [[0, 1, 2], [3, 4, 5], [6]]
    chunk([0, 1, 2, 3, 4, 5], 3); // [[0, 1, 2], [3, 4, 5]]
    chunk([0, 1, 2, 3, 4], 3); // [[0, 1, 2], [3, 4]]
    const emptyArr: any[] = [];
    chunk(emptyArr, 3); // []
    chunk(emptyArr, 3) !== emptyArr; // true
    chunk({} as any, 3); // []