Answers for "split into chunks javascript"

6

javascript array split chunk

const chunk = (arr, size) => arr.reduce((acc, e, i) => (i % size ? acc[acc.length - 1].push(e) : acc.push([e]), acc), []);

// Examples
chunk([1, 2, 3, 4, 5, 6, 7, 8], 3);     // [[1, 2, 3], [4, 5, 6], [7, 8]]
chunk([1, 2, 3, 4, 5, 6, 7, 8], 4);     // [[1, 2, 3, 4], [5, 6, 7, 8]]
Posted by: Guest on July-03-2020
0

how to split a string into chunks nodejs

function chunkString(str, length) {
  return str.match(new RegExp('.{1,' + length + '}', 'g'));
}
Posted by: Guest on October-30-2020

Code answers related to "split into chunks javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language