VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-chunk-method/

⇱ Lodash _.chunk() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.chunk() Method

Last Updated : 30 Aug, 2024

Lodash _.chunk() function is used to break the array into small chunks. Each chunk is an array of sizes as given.

Syntax:

_.chunk(array, size);

Parameters:

  • array: An array to be processed by chunk function.
  • size: This describes the size of the chunk.

Return Value:

It returns the array of chunks that is also an array.

Example 1: In this example, we are breaking the array by passing size '1' into the _.chunk() method.

Output:

👁 Image
OUTPUT EXAMPLE 1

Example 2: In this example, we are breaking the array by passing size '3' into the _.chunk() method. The size of chunk can be varied and array of different data type can be used with chunk function.

Output:

👁 Image

Example 3: In this example, we are breaking the 2d array by passing size '2' into the _.chunk() method. Using array of array with chunk.

Output:

👁 Image

Example 4: In this example, we are breaking the array of object by passing size '1' into the _.chunk() method.

Output :

👁 Image

Comment