Javascript replace all “ ” with a space

前端 未结 6 695
走了就别回头了
走了就别回头了 2020-12-02 20:00

Is there a way to replace every \"%20\" with a space using JavaScript. I know how to replace a single \"%20\" with a space but how do I replace all of them?

         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 20:28

    Use the global flag in regexp:

    var replaced = str.replace(/%20/g, " ");
                                    ^
    

提交回复
热议问题