📌  相关文章
📜  javascript 将数组拆分为块 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:39.535000             🧑  作者: Mango

代码示例5
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));