Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to check if a string contains only spaces in javascript

let str = "    ";
if (!str.replace(/s/g, "").length) {
  console.log("string only contains whitespace (ie. spaces, tabs or line breaks)");
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove element by class 
Javascript :: reactjs sass setup 
Javascript :: onclick jquery show alert 
Javascript :: loop through key value pairs js 
Javascript :: space between react native 
Javascript :: how to convert seconds into days hours seconds js 
Javascript :: js key is pressed 
Javascript :: javascript live time 
Javascript :: jquery check if input is empty on submit 
Javascript :: js update query string 
Javascript :: generate random number javascript 
Javascript :: local storage javascript array 
Javascript :: javascript add event listener to all input 
Javascript :: js create div 
Javascript :: how to get element by attribute value in javascript 
Javascript :: track window resize in vue 
Javascript :: if (!firebase.apps.length) { firebase.initializeApp({}); }else { firebase.app(); // if already initialized, use that one } 
Javascript :: document.ready 
Javascript :: random index js 
Javascript :: js response to json log 
Javascript :: react scroll to bottom of div 
Javascript :: console.log object object 
Javascript :: npm react hook form 
Javascript :: js pi 
Javascript :: javascript password generator example 
Javascript :: selected option attribute jquery 
Javascript :: Regex port number 
Javascript :: align left text in reactstrap 
Javascript :: Math.random javascript double 
Javascript :: difference between e.preventdefault and e.stoppropagation and return false 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =