Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript indexOf() - how to get specific index

Let's say I have a URL:

http://something.com/somethingheretoo

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

something like the equivalent of indexOf() which lets me input which instance of the backslash I want.

like image 252
Itai Sagi Avatar asked Sep 27 '11 13:09

Itai Sagi


1 Answers

let s = 'http://something.com/somethingheretoo';
parts = s.split('/');
parts.splice(0, 2);
return parts.join('/');
like image 89
PiTheNumber Avatar answered Oct 20 '22 00:10

PiTheNumber