Normalize Whitespace

Replace multiple consecutive whitespace characters with a single space and trim edges.

Code

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

Parameters

String with irregular whitespace

Browser·fetch() may be limited by CORS

More JavaScript Snippets