How to check if a single character is a whitespace in JavaScript

1 Answer

0 votes
const s = "Java    Script ";
          
s[1] === ' ' ? console.log('whitespace') : console.log('not whitespace');
s[5] === ' ' ? console.log('whitespace') : console.log('not whitespace');
  
  
  
  
/*
run:
    
"not whitespace"
"whitespace"
    
*/

 



answered Aug 7, 2021 by avibootz

Related questions

1 answer 293 views
1 answer 195 views
1 answer 245 views
2 answers 377 views
1 answer 349 views
...