二维数组

// 创建二维数组
Array.matrix = function (rows, cols, initial) {
    var arr = [];
    for (var i = 0; i < rows; i++) {
        var column = [];
        for (var j = 0; j < cols; j++) {
            column[j] = initial;
        }
        arr.push(column);
    }
    return arr;
};

 

posted @ 2016-07-07 18:48  koala_熊  Views(115)  Comments(0Edit  收藏  举报