Answers for "how to create chunk of array in javascript"

2

array chunk javascript

let input = [1,2,3,4,5,6,7,8,9];
let chunked = []
let size = 2;

for (let i = 0;  i < input.length; i += size) {
  chunked.push(input.slice(i, i + size))
}
console.log(chunked)
Posted by: Guest on June-13-2020
0

chunk an array

function __chunk(array, size) {
  let chunkArray = [];
  return function _chunk(chunk = array) {
    if (chunk.length < size) {
      return chunkArray.push(chunk) && chunkArray;
    }
    return chunkArray.push(chunk.slice(0, size)) && _chunk(chunk.slice(size));
  };
}
Posted by: Guest on May-13-2020

Code answers related to "how to create chunk of array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language