var spacesString= "Do I have spaces?"; var noSpacesString= myString.replace(/ /g,'');// "DoIhavespaces?"
var str = " Some text "; str.trim();
if (/\s/.test(str)) { // It has any kind of whitespace }
//Removing whitespace from String var str = " Hello World! "; console.log(str.trim());
Whitespace is empty space (without any visual representation) on screen. Examples of whitespace characters include space characters, tabs, and line break characters.