remove trailing spaces js code example

Example 1: javascript remove all whitespaces

var spacesString= "Do I have spaces?"; 
var noSpacesString= myString.replace(/ /g,'');// "DoIhavespaces?"

Example 2: javascript remove space from string

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

// Example
removeSpaces('hel lo wor ld');      // 'helloworld'

Example 3: js remove space before string

var str = "  Some text ";
str.trim();
// str = "Some text"

Example 4: js remove spaces

str = str.trim();

Example 5: remove space from string javascript

var puzzle1=myTrim($("#puzzleinput").val());
            function myTrim(x) {
              return x.replace(/^\s+|\s+$/gm,'');
            }

Tags:

Php Example