wordCount
Counts the number of words in a string.
Syntax
typescript
wordCount(str: string): numberParameters
| Parameter | Type | Description |
|---|---|---|
str | string | The input string. |
Returns
| Type | Description |
|---|---|
number | The number of words in the string. |
Example
typescript
wordCount("Exemplo de string"); // 3
wordCount(" Teste word count "); // 3
wordCount(""); // 0Notes
- Throws
TypeErrorif the argument is not a string. - Words are separated by whitespace.
