Utility function to split an array into batches of a specified size.

const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const batches = arrayBatch(items, 3)
// Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

If batchSize is not a positive integer

  • Type Parameters

    • T = any

    Parameters

    • inputArray: T[]
    • batchSize: number = 1

    Returns T[][]