<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 check if first string contains all characters of second string
Example to take user input and display on screen using JavaScript
jQuery check if an element is visible or hidden
Using jQuery add new table row on click
JavaScript convert string variable in boolean using Regex
How to set checkbox and radio option checked on load with jQuery?