Trim Extra Whitespace

Remove extra whitespace from a string, keeping single spaces between words.

Code

General
str.trim().replace(/\s+/g, ' ');

Parameters

The string to clean up

Browser·fetch() may be limited by CORS

More JavaScript Snippets