JavaScript indexOf() - how to get specific index

前端 未结 8 584
野趣味
野趣味 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:31

    Another approach is to use the Javascript "split" function:

    var strWord = "me/you/something";
    var splittedWord = strWord.split("/");
    

    splittedWord[0] would return "me"

    splittedWord[1] would return "you"

    splittedWord[2] would return "something"

提交回复
热议问题