Javascript replace all “ ” with a space

前端 未结 6 676
走了就别回头了
走了就别回头了 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条回答
  •  隐瞒了意图╮
    2020-12-02 20:35

    Check this out: How to replace all occurrences of a string in JavaScript?

    Short answer:

    str.replace(/%20/g, " ");
    

    EDIT: In this case you could also do the following:

    decodeURI(str)
    

提交回复
热议问题