Answers for "es6 split number to array into chunks"

1

split array into chunks javascript

Array.prototype.chunk = function(size) {
    let result = [];
    
    while(this.length) {
        result.push(this.splice(0, size));
    }
        
    return result;
}

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(arr.chunk(2));
Posted by: Guest on August-19-2020

Code answers related to "es6 split number to array into chunks"

Code answers related to "Javascript"

Browse Popular Code Answers by Language