0% found this document useful (0 votes)
20 views1 page

JavaScript Chunk Array Function

The document contains a JavaScript function that splits a given array into smaller arrays (chunks) of a specified size. The function 'chunkArrayInGroups' takes an array and a number as parameters, slices the array into chunks, and returns a two-dimensional array containing the chunks. The example provided uses an array of numbers from 0 to 5 and divides it into groups of 3.

Uploaded by

savepasa1122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

JavaScript Chunk Array Function

The document contains a JavaScript function that splits a given array into smaller arrays (chunks) of a specified size. The function 'chunkArrayInGroups' takes an array and a number as parameters, slices the array into chunks, and returns a two-dimensional array containing the chunks. The example provided uses an array of numbers from 0 to 5 and divides it into groups of 3.

Uploaded by

savepasa1122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

let array = [0, 1, 2, 3, 4, 5];

let num = 3;
let devide = [Link]/num
let twoDArray = []
function chunkArrayInGroups(array, num) {
let startCount = 0
for (let i = 0; i < devide; i++){

let dividedArr = [Link](startCount, num + startCount)

startCount = startCount + num

[Link](dividedArr)

}
return twoDArray
}
[Link](chunkArrayInGroups(array, num))

You might also like