Description

Create an array of elements split into groups the length of size.

Syntax

chunk(array, size)

Parameters

Input ParameterTypeDescription
arrayArrayThe array to process
sizenumberThe length of each chunk

Return value

Type
Array<Array<any>>
ExampleResultDescription
chunk(['a', 'b', 'c', 'd'], 2)[['a', 'b'], ['c', 'd']]Returns the new array of chunks with size 2
chunk(['a', 'b', 'c', 'd'], 3)[['a', 'b', 'c'], ['d']]Returns the new array of chunks with size 3.

To view all the List functions, click here.

See Also