Q:

how to remove spaces in javascript

str.replace(/\s+/g, '')
6
.replace(/ /g,'')
1
const removeSpaces = str => str.replace(/\s/g, '');

// Example
removeSpaces('hel lo wor ld');      // 'helloworld'
1
str = str.replace(/\s/g, '');
0
string.split(" ").join("")
0
str = str.trim();
1
var str = '/var/www/site/Brand new document.docx';

document.write( str.replace(/\s/g, '') );
0
var a = b = " /var/www/site/Brand new   document.docx ";

console.log( a.split(' ').join('') );
console.log( b.replace( /\s/g, '') ); 
0

New to Communities?

Join the community