How to get the last part of a string in JavaScript?

后端 未结 6 1373
野趣味
野趣味 2020-12-23 16:22

My url will look like this:

http://www.example.com/category/action

How can I get the word \"action\". This last part of the url (after the last forward slash

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 16:52

    Or the regex way:

    var lastPart = url.replace(/.*\//, ""); //tested in FF 3
    

    OR

    var lastPart = url.match(/[^/]*$/)[0]; //tested in FF 3
    

提交回复
热议问题