![]() |
VOOZH | about |
The chunk() function breaks the collection to many small collections of the given size. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.
Syntax:
data.chunk(x)
Parameter: This function accepts a single parameter as mentioned above and described below.
Return value: Return the sub collection of the main collection
Below examples illustrate the chunk() function in collect.js:
Example 1: Here in this example, we take a collection and then using the chunk() function we divide the collection.
Output :
[ Collection { items: [ 1, 2, 3, 4, 5 ] },
Collection { items: [ 6, 7 ] } ]
Example 2: In this example, we will pass two values in the chunk() function.
Output:
[ Collection { items: [ 0, 1 ] },
Collection { items: [ 2, 3 ] },
Collection { items: [ 4, 5 ] },
Collection { items: [ 6 ] } ]