Javascript - How to remove all extra spacing between words

前端 未结 7 1722
闹比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:29

    var str = "    This    should  become   something          else   too . "
    $.trim(str).replace(/\s(?=\s)/g,'')
    

    This uses lookahead to replace multiple spaces with a single space.

提交回复
热议问题