xxxxxxxxxx
const removeSpaces = str => str.replace(/\s/g, '');
// Example
removeSpaces('hel lo wor ld'); // 'helloworld'
xxxxxxxxxx
var a = b = " /var/www/site/Brand new document.docx ";
console.log( a.split(' ').join('') );
console.log( b.replace( /\s/g, '') );
xxxxxxxxxx
var str = '/var/www/site/Brand new document.docx';
document.write( str.replace(/\s/g, '') );
xxxxxxxxxx
var str = '/var/www/site/Brand new document.docx';
document.write( str.replace(/\s/g, '') );
Run code snippetHide results
xxxxxxxxxx
str.replace(/\s+/g, '') //Replace str with variable name you have string saved too.
xxxxxxxxxx
const stringWithSpaces = "Hello World";
const stringWithoutSpaces = stringWithSpaces.replace(/\s/g, "");
console.log(stringWithoutSpaces); // Output: "HelloWorld"