Q:

js remove space from string

str.replace(/\s+/g, '')
6
var str = "  Some text ";
str.trim();
// str = "Some text"
9
string.split(" ").join("")
0
const removeSpaces = str => str.replace(/\s/g, '');

// Example
removeSpaces('hel lo wor ld');      // 'helloworld'
1
str = str.replace(/\s/g, '');
0
var str = "       Hello World!        ";
alert(str.trim());
5
newString = string.replace(/\s+/g,' ').trim();
0
str = str.trim();
1
var puzzle1=myTrim($("#puzzleinput").val());
            function myTrim(x) {
              return x.replace(/^\s+|\s+$/gm,'');
            }
0

New to Communities?

Join the community