check for whitespace javascript code example

Example 1: javascript remove all whitespaces

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

Example 2: check whitespace in javascript

if (/\s/.test(str)) {
    // It has any kind of whitespace
}

Example 3: js find space in string

if(str.indexOf(' ') >= 0){
    console.log("contains spaces");
}

Example 4: what is whitespace javascript

Whitespace is empty space (without any visual representation)
 on screen. Examples of whitespace characters include 
 space characters, tabs, and line break characters.

Tags:

Html Example