如何在javascript中将1d数组的元素推入9x9数组?

时间:2018-01-23 15:55:46

标签: javascript arrays multidimensional-array

在javascript中为我的数独求解器插入数组的值到9x9多维数组时遇到问题。

var sudoku = Array(9).fill(null).map( ()=>Array(9).fill(null) ); // creates an empty 9x9 array

var problemString = "1-58-2----9--764-52--4--819-19--73-6762-83-9-----61-5---76---3-43--2-5-16--3-89--"; //sample sudoku problem in string format
var problemArray = problemString.split(''); // turns the problem string into an array


for(i=0; i<problemArray.length; i++){
    for(j=0; j<problemArray.lenght; j++){
        sudoku[i][j]=(problemArray[i]); 
    }
}

console.log(sudoku); 

/*[ [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ],
    [ null, null, null, null, null, null, null, null, null ] ]*/

0 个答案:

没有答案