how to remove spaces from strings javascript

JavaScript
var str = "       Hello World!        ";
alert(str.trim());var str = '/var/www/site/Brand new document.docx';

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

Also in JavaScript: