I make a script. That get the href of the element. But i want only the last part of this url. I make this:
var newURL = $(".list-portfolio a").attr("href");
pathArray = newURL.split( '/' ),
secondLevelLocation = pathArray[0];
var newPathname = "";
for ( i = 3; i < pathArray.length; i++ ) {
newPathname += "/";
newPathname += pathArray[i];
}
this results in this /portfolio/ruimzicht.html Thats almost good. How can i remove the first /.
Do you have any tips to improve the code?
Why not use an array function?
If you’re just interested in the last part anyway, you could shrink this into a one liner: