Remove all white space from string JavaScript

javascript, replace, string, trim

Solution

Use this:

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

Instead of this:

str.trim()

Problem

How can I remove all the white space from a given string. Say: ``` var str = " abc de fog "; str.trim(); ``` Gives `abc de fog` AND NOT `abcdefog`, which I want. How can I get all the white space removed using JavaScript?

Original source

Related problems