JavaScript indexOf() - how to get specific index

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

    s = 'http://something.com/somethingheretoo';
    parts = s.split('/');
    parts = parts.slice(0, 2);
    return parts.join('/');
    

提交回复
热议问题