VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-chunk-function/

⇱ Collect.js | chunk() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js | chunk() Function

Last Updated : 12 Jun, 2020

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.

  • x : This parameter holds an integer number that defines where to break the collection

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 ] } ]
Comment
Article Tags: