<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
JavaScript simple alert on Click
JavaScript calculate Fahrenheit from Celsius
jQuery move multi select values from one to another multi select list
jQuery check if an element is visible or hidden
How to set checkbox and radio option checked on load with jQuery?
Image Rollover Using onMouseOver and onMouseOut