Get parts of URL after domain name //... by splitting URL into array

Viewed 25937

I have make this code:

var newURL = $(".list-portfolio a").attr("href"),
    pathArray = newURL.split( '/' ),
    secondLevelLocation = pathArray[0];
console.log(pathArray);

    var pathArray = pathArray[3, 4];

The pathArray value is ["http:", "", "www.mikevierwind.nl", "portfolio", "ruimzicht.html"]

How can i get the last 2 items of this array. I want that the results is portfolio/ruimzicht.html.

6 Answers
location.href.substr(location.href.indexOf(location.host)+location.host.length)

try this

console.log(new URL(document.URL));

you would get object of URL

Related