js remove space from string

JavaScript
str.replace(/\s+/g, '')var spacesString= "Do I have spaces?"; 
var noSpacesString= myString.replace(/ /g,'');// "DoIhavespaces?"string.split(" ").join("")var str = "       Hello World!        ";
alert(str.trim());str = str.trim();var str = '/var/www/site/Brand new document.docx';

document.write( str.replace(/\s/g, '') );
Source

Also in JavaScript: