Detect if string contains any spaces

后端 未结 5 704
醉酒成梦
醉酒成梦 2020-12-23 11:24

How do I detect if a string has any whitespace characters?

The below only detects actual space characters. I need to check for any kind of whitespace.



        
5条回答
  •  遥遥无期
    2020-12-23 12:03

    var string  = 'hello world';
    var arr = string.split(''); // converted the string to an array and then checked: 
    if(arr[i] === ' '){
       console.log(i);
    }
    

    I know regex can do the trick too!

提交回复
热议问题