<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 check a variable is undefined in JavaScript?
jQuery simple form validations between start date and end date
JavaScript example to change image on click
JavaScript HTML5 Validation for name and email field
How to join string with number in JavaScript?
How to show hide option list items using jQuery?