Q:

check whitespace in javascript

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

New to Communities?

Join the community