Workshop › Connect Four › Step 7 of 38
The game must remember what is in every hole. The board becomes a 2D array: a list of 6 rows, each a list of 7 cells.
board[row][col] is 0 for empty, 1 for red and 2 for yellow. Every row must be its own new array.
```js
let board // board[row][col]: 0 empty, 1 or 2
function reset() {
board = Array.from({ length: ROWS }, () => Array(COLS).fill(0))
}
reset()
```Array(COLS).fill(0) is a row of seven 0s.Array.from({ length: ROWS }, () => ...) calls the arrow function once per row, so each row is a new array.Array(ROWS).fill(Array(COLS).fill(0)) would put the same row six times: change one, change all.let board and reset.draw() call at the bottom, write reset().Skills: Arrays and objects
← All 42 holes Discs in their colors →