JavaScript indexOf() - how to get specific index

前端 未结 8 682
野趣味
野趣味 2021-01-18 02:02

Let\'s say I have a URL:

http://something.com/somethingheretoo

and I want to get what\'s after the 3rd instance of /?

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-18 02:32

    If you know it starts with http:// or https://, just skip past that part with this one-liner:

    var content = aURL.substring(aURL.indexOf('/', 8));
    

    This gives you more flexibility if there are multiple slashes in that segment you want.

提交回复
热议问题