Answers for "chunck on array"

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
2

php chunk array

$array=['a','b','c','d','e','f','g'];
$chunckedArray=array_chunk($array,3);
//output: $chunkedArray=[['a','b','c'],['d','e','f'],['g']]
//Array ( [0] => Array ( [0] => a [1] => b [2] => c ) [1] => Array ( [0] => d [1] => e [2] => f ) [2] => Array ( [0] => g ) )
Posted by: Guest on August-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language