I want to get a specific part of a url between the third and fourth slashes of a link on the page.
EDIT: Sorry I don\'t think I was clear the first time, I meant get
I'd suggest:
var link = 'http://www.example.com/directory1/directory2/directory3/directory4/index.html'; console.log(link.split('/')[5]);
JS Fiddle demo.
The reason we're using [5] not [4] is because of the two slashes at the beginning of the URL, and because JavaScript arrays are zero-based.
[5]
[4]