Count Words

Count the number of whitespace-separated words in a string.

Code

General
str.trim() ? str.trim().split(/\s+/).length : 0;

Parameters

The string to count words in

Browser·fetch() may be limited by CORS

More JavaScript Snippets