How can I change the last component of a url path?

前端 未结 7 855
一整个雨季
一整个雨季 2021-02-09 03:15
\"http://something.com:6688/remote/17/26/172\"

if I have the value 172 and I need to change the url to 175

\"http://something.com:6688/         


        
7条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 04:07

    Split the String by /, remove the last part, rejoin by /, and add the new path

    newurl = url.split('/').slice(0,-1).join('/')+'/175'
    

提交回复
热议问题