Workshop › Conway's Game of Life › Step 5 of 32
The picture is not the world; the world is data. Each cell is a number, 1 alive and 0 dead, and the grid is a list
of rows, each row a list of cells: grid[row][col]. We make an all-dead grid.
```js
let grid // grid[row][col]: 1 alive, 0 dead
const emptyGrid = () => Array.from({ length: ROWS }, () => Array(COLS).fill(0))
function reset() {
grid = emptyGrid()
}
reset()
draw()
```let grid makes a variable whose value can change later (const cannot). It is empty until reset fills it.emptyGrid is a short arrow function: it returns whatever is right of =>.Array(COLS).fill(0) is one row of 60 zeros. Array.from({ length: ROWS }, () => ...) calls the little function
48 times and makes a list of the 48 results: a new row each time.reset() puts a fresh empty grid in grid; it runs once, before the first draw().const TOP = 36, after an empty line, write let grid, emptyGrid and reset as shown.reset() above draw(). Press Run.Skills: Arrays and objects
← A function that draws Draw every living cell →