Underscore.js _.chunk() Function Last Updated : 24 Nov, 2021 Comments Improve Suggest changes Like Article Like Report _.chunk() function: It is used to split a passed array into a number of arrays containing the number of elements given in the second parameter of the _.chunk() function.We can convert a single array into a number of arrays using this function.Also, the number of elements which the resultant array will contain should be given in the second parameter. Syntax: _.chunk(array, length) Parameters:It takes two arguments: The arrayThe length of the resultant arrays Return value: It returns the number of arrays that are formed after the split. Examples: Passing a list of numbers to _.chunk() function: The _.chunk() function takes the element from the list one by one and forms an array until the number of elements in the resultant array is equal to the given number in the second parameter. Then, if the elements in the given array are still present then it forms another array in the result. Finally, the total number of arrays formed is equal to the number of elements in the passed array divided by the number given in the second element. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.chunk([1, 2, 3, 4, 5, 6], 2)); </script> </body> </html> Output: Passing a larger array size to the _.chunk() function:If we pass a larger sized number in the second parameter then also it works in the same way. Like here the number of elements is given is 3. So, we form the number of arrays. Each array has three elements in the same order it is present in the passed array. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)); </script> </body> </html> Output: Passing a list of characters to the _.chunk() function:Even if we pass the array containing alphabets .i.e., string of characters rather than numbers then also it will work in the same manner. This implies that the _.chunk() function does not distinguish between numbers, characters, etc. Also, since here the number passed in the second parameter is a two but the passed array has five elements. Therefore, the last element will have only one element. It will not give any error. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log( _.chunk(['HTML', 'CSS', 'JS', 'AJAX', 'PEARL'], 2)); </script> </body> </html> Output: Having the same number of the array as the number of elements to the _.chunk() function:We can even obtain the result the same number as the elements passed in the array. This makes the use of _.chunk() function more convenient. For this, we just need to pass the second parameter as 1. This implies that the size of each array will be one. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log( _.chunk(['HTML', 'CSS', 'JS', 'AJAX', 'PEARL'], 1)); </script> </body> </html> </html> Output: NOTE: These commands will not work in Google console or in firefox as for these additional files need to be added which they didn't have added. So, add the given links to your HTML file and then run them. The links are as follows: html <script type="text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> An example is shown below: Comment More infoAdvertise with us Next Article Underscore.js _.chunk() Function S Sakshi98 Follow Improve Article Tags : JavaScript Web Technologies JavaScript - Underscore.js Similar Reads Underscore.js _.chain() Function Underscore.js _.chain() function is an inbuilt function in the Underscore.js library of JavaScript which is used to find a wrapped object. Moreover, invoking the methods on this object will continue to return the wrapped objects until the value is invoked. Syntax:_.chain(obj);Parameters:obj: It is t 1 min read Underscore.js _.each() Function Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. The _.each() function is an inbuilt function in Underscore.js library of JavaScript which is used to retu 3 min read Underscore.js _.after() Function Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc even without using any built-in objects. The _.after() function is an inbuilt function in Underscore.js library of JavaScript which is used to cre 2 min read Underscore.js _.first() Function Underscore.js  _.first() function is used to return the first element of the array, i.e. the number at the zeroth index. It returns the first n elements in the array of m size (n < m) by just passing the variable n in the array. It is a very easy-to-use function of the underscore.js library and i 3 min read Underscore.js _.zip() Function The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke etc even without using any built-in objects. The _.zip() function matches each passed array of elements to the next passed array element. It is used when more than one homogeneous arrays (o 3 min read Like