<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 change text color on click using JavaScript?
How to change the height of Textarea on click?
How to scroll page to particular Div on click using jQuery?
Edit the text of label on click using jQuery
Using jQuery delete table row on click
How to declare and print value of variable in JavaScript?