Workshop › Snake › Step 13 of 28
The trick of Snake: to move, add a new head in front and remove the last cell. The body follows by itself.
```js
function update() {
const head = { x: snake[0].x + dir.x, y: snake[0].y + dir.y }
snake.unshift(head)
snake.pop()
}
```snake[0] is the current head. The new head is one step from it in the direction dir.unshift puts the new head at the front of the array; pop removes the last item (the tail).let head = { x: 5, y: 5 }.update with the three new ones.Skills: Arrays and objects
← A body made of a list Pick a spot for the food →