👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

How to check if a JavaScript string is empty or contains only spaces?

To check if a JavaScript string is empty or contains only spaces, trim the content and check if the string is empty:

var str='  ';
if (!str.trim()) {
    // Do something, the string is empty or contains only spaces
}

More