开满天机
如果所有单元格都是“空的”,则让所有单元格都包含一个空格字符可能更有意义。看看这里:var Cell_1 = "a";var Cell_2 = " ";var Cell_3 = " ";var Cell_4 = " ";var Cell_5 = " ";var Cell_6 = " ";var Cell_7 = " ";var Cell_8 = " ";var Cell_9 = " ";console.log(Cell_1 + "|" + Cell_2 + "|" + Cell_3 + "\n" +Cell_5 + "|" + Cell_6 + "|" + Cell_6 + "\n" +Cell_7 + "|" + Cell_8 + "|" + Cell_9 + "\n" +)这样你所有的变量都是相同的宽度 - 一个字符。为了将来参考,这里有一些代码可能看起来更好一些:// This is called a 2d array: essentially an array containing other arrays.// Its good for storing grids or tables of information.var cells = [ ['a', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]// This uses Array.reduce() to generate the string.// Google it once you feel more confident :)console.log( cells.reduce( (totalString, currentRow) => totalString + currentRow.join('|') + '\n', '' ))