Check if a single character is a whitespace?

后端 未结 9 1191
清酒与你
清酒与你 2021-02-06 21:21

What is the best way to check if a single character is a whitespace?

I know how to check this through a regex.

But I am not sure if this is the best way if I onl

9条回答
  •  伪装坚强ぢ
    2021-02-06 21:42

    The regex approach is a solid way to go. But here's what I do when I'm lazy and forget the proper regex syntax:

    str.trim() === '' ? alert('just whitespace') : alert('not whitespace');
    

提交回复
热议问题