Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const arr = ['a','b','c','d','e','f','g'];
- const chunkArray = (array, length) => {
- let newArr = [];
- let temp = [];
- for(let i = 0; i < array.length; i++){
- temp.push(array[i]);
- if((i+1)%length===0 && i!==0){
- newArr.push(temp);
- temp = [];
- }
- }
- newArr.push(temp);
- return newArr;
- }
- console.log(chunk(arr, 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement