Question #6   Submitted by Answiki on 04/27/2020 at 04:59:13 PM UTC

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

Answer   Submitted by Answiki on 04/27/2020 at 05:38:29 PM UTC

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
}

5 events in history
Answer by Answiki on 04/27/2020 at 05:38:29 PM

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
}

Answer by Answiki on 04/27/2020 at 05:37:59 PM

To check if a JavaScript string is empty or contains only space, 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
}

Answer by Answiki on 04/27/2020 at 05:37:27 PM

To check if a JavaScript string is empty or contains only space, 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
}

Answer by Answiki on 04/27/2020 at 05:36:11 PM

To check if a JavaScript string is empty or contains only space, 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
}

Question by Answiki 04/27/2020 at 04:59:13 PM
How to check if a JavaScript string is empty or contains only spaces?
# ID Query URL Count

Icons proudly provided by Friconix.