goldies
    Preparing search index...

    Function chunk

    • Splits an array into chunks of a given size.

      The last chunk is shorter when the array doesn't divide evenly. The input array isn't changed.

      Type Parameters

      • T

      Parameters

      • array: readonly T[]

        The array to split.

      • size: number

        The length of each chunk: a positive integer.

      Returns T[][]

      The chunks, in order.

      If size isn't a positive integer.

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

      // Send at most 100 records per request
      for (const batch of chunk(records, 100)) {
      await save(batch);
      }