remove all whitespace from string javascript code example

Example 1: javascript remove all whitespaces

var spacesString= "Do I have spaces?"; 
var noSpacesString= myString.replace(/ /g,'');// "DoIhavespaces?"

Example 2: remove all spaces from a string javascript

.replace(/ /g,'')

Example 3: javascript remove all spaces from string

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

Example 4: delete backspace on string js

// str1 your string with backspace 
var str1 = 'Hello world xd lol'
var str2 = ''
// str2 string without empty 
str2 = str1.replace(/\s/g, '')
console.log(str2)
// "Helloworldxdlol"

Example 5: remove whitespace javascript

var str = "  Some text ";
str.trim();