1const removeSpaces = str => str.replace(/\s/g, '');
2
3// Example
4removeSpaces('hel lo wor ld'); // 'helloworld'
1var str=" I have outer spaces ";
2var cleanStr=str.trim();//trim() returns string with outer spaces removed
1var str = '/var/www/site/Brand new document.docx';
2
3document.write( str.replace(/\s/g, '') );