js split array into smaller arrays

Array.prototype.chunk = function(n) {
  if (!this.length) {
    return [];
  }
  return [this.slice(0, n)].concat(this.slice(n).chunk(n));
};
console.log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].chunk(5));

4
3
Yukiko H 110 points

                                    Array.prototype.chunk = function(size) {
    let result = [];
    
    while(this.length) {
        result.push(this.splice(0, size));
    }
        
    return result;
}

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(arr.chunk(2));

4 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript split array into chunks of size n array into chunks js separate array into chunks javascript split an array to a certain size js javacsrip[t split an array into chunks javascript es6 split array into chunks javascript split string into chunks split array to chunks javascript split array into chunks of size n javascript split array into chunks of size n split array elements to more arrays javascript split array into to chunks typescript split array into three chunks split string into chunks js split in chunks array hs split into chunks javascript array es6 split array into even chunks split array of n elements into chunks js split array into two chunks from index js split array by size typescript split array into chunks nodejs split into chunks javascript split an array into chunks 5 values per array split array into n batches javascript array into chunks javascript split an array into chunks js split an array to smaller arrays split array into n parts javascript js break array into smaller arrays js large array split into 100 length chunks js large array split into chunks how to split an array into more arrays in javascript split array into chunks typescript array chunks to single array split array every n elements js es6 split array every n elements js javascript divide an array into chunks how to split a big array to specific size array in js split array into chunks of n length javascript split array into parts of certain size js js how to split chunks array to get new array more length divide array into chunks javascript javascript divide array into smaller arrays js slice array into chunks split array into chunks in javascript split array in chunks javascript split array into smaller arrays based on contents javascript es6 split array into chunks split array into 12 chunks Split an array into chunks dynamically in JavaScript split string into chunks javascript how to split an array into chunks in javascript js split array to chunks by value js split array to chunks js split array into chunks of 2 how to split the array to smaller array using javascript split into size based chunks javascript divide array into chunks es6 split number to array into chunks js split array into chunks of n split array in 3 arrays javascript seprate array into chunks split javascript array into chunks based on attribute split javascript array into chunks javascript break array into chunks split large array into chunks js split large array into chunks javascript split larger number into array of integers javascript break array into smaller arrays split array into chunks when item is split list into chunks javavscript javascript split array into equal chunks javascript split array into chunk split list into chunks javascript js split array into chunks how to split array into chunks javascript split array into smaller arrays how to split the array into chunks split array into chunks nodejs typescript split array into chunks of split array to n chunks js split array in chunks javascript split array to chunks js array split into chunks split every 4 element in array in javascript split array with equal length js js split string into chunks how to divide an array to four equal arrays typescript javascript split an array into multiple arrays slice into equal sized arrays javascritp How can you get a small part of an array js js array into sections breaking an array into pieces javascript js chunks javascript split string in chunks how to split arrays into multiple arrays javascript split array into two js split array into smaller arrays split array into chunks how to divide an array in javascript create subarray from array javascript every 3 elements array_chunk in node js make list into multiple arrays javascript how to get chunks individually javascript how to split array or items into an array of smaller arrays javascript how to split array elements in ts js split array into multiple arrays split array into 3 arrays javas split array into 3 arrays javascript typescript get a smaller array out of a bigger array split array into n chunks javascript batch array node how to make one big array from two small array split array into smaller arrays javascript break array into every 5 elements split array buffer into chunks breaking up large array into subarray js javascript es6 split array node processing lengthly for loop in chunck javascript split array into multiple arrays based on value divide array into array of arrays javascript C split 100 number array in 10 times divide data in chucks js divide array into equal parts seperate an array into tiny arrays how to split an array of arrays divide array into smaller arrays js divide string into chunks javascript chunk function javascript sort chunks of arrays javascript divide array into multiple arrays divide big array into multiple arrays javascript getting equal chunks from array in js getting chunks from array in js split array into small arrays split array in dimensions javascript javascript split array by groups of 3 javascript cut array in same size chunk array using jquery split array into multiple arrays javascript how to divide an array into subarrays in node js es6 slice massive array to children array javascript split array in smaller arrays how to chunk array by special condition split array into two arrays javascript break array into chunks javascript break array into smaller arrays js change array to smaller array\ split array into individual arrays chunk an array into values how to turn array into many array get smaller arrar from array javascript split array into arrays split mapped data into two chunks split array to multiple arrays javascript split an array into multiple arrays javascript split an array into multiple arrays javascript split array into chunks dos split function only work on array give a function of array = [1,2,3,4,5,6,7,8,9,10] // cut out 5 & 6 then // give me new array = [1,2,3,4,7,8,9,10] using splice array java script how to separate an array into multiple arrays of every nth element how to separate an array into multiple arrays process batches in array js array_chunk in javascript splitting array to many arrays split array to multiple arrays javascript array number split build your own chunk function javascript small arrays to big array js small arrays to array js break array into smaller arrays split array in groups of 100 split up an array into other arrays javascript array chunk other arrays javascript array split by size divide array into parts javascript How to split an array into chunks of the same size java how to break big array to multiple arrays Json response in chunk arrays of 100 results Split array in array of 10 how to split an array into multiple arrays split every 3 element javascript js array different chunks devide array on elements js split array in small array cut into pieces snalle element inside an array javascript array chunk map javascript seperate arrays with numbers into different arrays slice array into 9000x1 javascript group array into chunks divide array per index javascript how to divide array subarray in javascript split collection to list item javascript split array into multiple arrays java divide array into equal parts with remaider split array in certain nomber splitarray js javascript split array into groups of 3 split an array into groups of 3 chunks.js how to split up a section of an array reduce array into smaller array javascript split array in smaller arrays array to divide in size divide array by x js split array by 3nth js split array by 3s nodejs chunk array package How many time to split an array of 10 items javascript break array on index range split array in middle and get next element in nodejs js divide array in chunks node js split array into chunks how to splice and view array in chunks by previous chunks and next chunks in js js split arr in 3 other javascript split array into chunks based on value how to chunk array of objects in javascript split array javascript 2 elements javascript split large array into chunks javascript slice array into chunks create a fixed array chunk from variable in js how to cut an arry each two split large array into chunks node how to break array into chunks in js javascript split array into chunks es6 split array into multiple parts slice array in chunks of length slice divide array in two javascript split map chunks separate an array length 100 javascript js devide array in multiples how to separate an arry of json into equal es6 how to break up an arrays of array js split array with cocomma point in javascript split list into chunks js split array in subarrays how to get a chunk of an array in typescirpt splitting array into chunks in one line split arrays into array of no more than 3 split array js es6 separate an array in pieses how to break an array into s js split an array into chunks javascript split array in chunks chunk array in 3 javascript break array into elements javascript how to divide a long array onto multiple arrays array_chunk js I havea map that divides elements by 4 how do I seperate those javascript split an array in to multiple arrays how to effectively seperate array into subarrays javascript native array chunk copy javascript divide array into group of four elements array function to break array into smaller arrays javascript break array into smaller arrays javascript split array to different arrays javascript divide array javascript split array into chunks javascript javascript subdivide array js splice arr to batches divide arrays javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source