Skip to content

chunk

Splits array arr into sub-arrays with the length of length.

Added in v0.0.2

Usage

ts
import { chunk } from 'parsnip-kit'

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

API

Type Parameter

ArgTypeDescription
TType of elements of array to split

Arguments

ArgTypeOptionalDefaultDescription
arrT[]falseundefinedThe array to split
lengthlengthfalseundefinedThe length of sub-arrays

Returns

Type
T[][]