📌  相关文章
📜  javascript 将数组转换为矩阵 - Javascript 代码示例

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

代码示例1
function listToMatrix(list, elementsPerSubArray) {
    var matrix = [], i, k;

    for (i = 0, k = -1; i < list.length; i++) {
        if (i % elementsPerSubArray === 0) {
            k++;
            matrix[k] = [];
        }

        matrix[k].push(list[i]);
    }

    return matrix;
}