remove space from string javascript

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

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

Also in JavaScript: