The _.chunk()
method in Lodash is used to reduce an array into multiple chunks, where each chunk is also an array of a specified size.
_.chunk(array, size)
This method accepts the following parameters:
array
: This is the array to be reduced.size
: This is the size of the chunk.This method returns an array of chunks.
Let’s look at an example of the _.chunk()
method in the code snippet below:
In the HTML tab:
lodash
script.In the JavaScript tab:
size
and initialize it with 2
._.chunk()
method to reduce the array into small chunks.