<script>
var new2darr = chunkArrayInGroups(["A", "B", "C", "D", "E", "F"], 4);
console.log(new2darr); // [["A", "B", "C", "D"], ["E", "F"]]
function chunkArrayInGroups(arr, size) {
const newArr = [];
let i = 0;
while (i < arr.length) {
newArr.push(arr.slice(i, i + size));
i += size;
}
return newArr;
}
</script>
Most Helpful This Week
How to scroll page to particular Div on click using jQuery?
JavaScript simple alert on Click
JavaScript check if first string contains all characters of second string
Image Rollover Using onMouseOver and onMouseOut
How to declare and print value of variable in JavaScript?
How to declare multiple variables in one statement in Javascript?