Javascript - How to remove all extra spacing between words

前端 未结 7 1725
闹比i
闹比i 2020-12-05 02:03

How can I remove all extra space between words in a string literal?

\"some    value\"

Should become

\"some value\"
<         


        
7条回答
  •  天命终不由人
    2020-12-05 02:43

    var str = "    This    should  become   something          else   too . ";
    str = str.replace(/ +(?= )/g,'');
    

    Here's a working fiddle.

提交回复
热议问题