Workshop › Chess › Step 4 of 48
The board needs data: what stands on each square. We write the starting position the way chess players do, one text
per row, and turn it into board: an array of 8 rows, each an array of 8 letters.
```js
// Row 0 is black's back rank at the top, row 7 white's at the bottom. Capitals are white.
const START = ['rnbqkbnr', 'pppppppp', '........', '........', '........', '........', 'PPPPPPPP', 'RNBQKBNR']
let board // board[row][col]: '' or a color and a kind, like 'wN' or 'bQ'
function reset() {
board = START.map((line) => [...line])
}
reset()
draw()
```START is an array of 8 texts, row 0 (black's pieces) first.let board is a variable that will hold the position; reset() fills it.map makes a new array by running a function on each item. (line) => [...line] is a short function that splits
a text into its letters: [...'rn.'] is ['r', 'n', '.'].board[0][4] is 'k': row 0, column 4, the black king.TOP line write START, board and reset (with the empty lines).draw() call at the bottom write reset().Skills: Arrays and objects
← All 64 squares Color and kind →