Workshop › Text detective › Step 4 of 13
To count words we cut the text at every space. split(' ') gives an array of pieces; its length is the word count.
```js
const words = box.value.split(' ')
result.textContent = 'Characters: ' + box.value.length + '\nWords: ' + words.length
```split(' ') returns an array: 'the cat sat' becomes ['the', 'cat', 'sat'].'\n' is a line break, so the word count goes on its own line.Inside update, add the words line and extend the text as shown.
Skills: Arrays and objects
← Update as you type The extra-space trap →