what I would do is make a function that takes an index of what part you want.. that way you can get any part anytime
getPathPart = function(index){
if (index === undefined)
index = 0;
var path = window.location.pathname,
parts = path.split('/');
if (parts && parts.length > 1)
parts = (parts || []).splice(1);
return parts.length > index ? parts[index] : null;
}
with this you can of course make changes like a getLastIndex flag that when true you can return that..
getPathPart = function(index, getLastIndex){
if (index === undefined)
index = 0;
var path = window.location.pathname,
parts = path.split('/');
if (parts && parts.length > 1)
parts = (parts || []).splice(1);
if(getLastIndex){
return parts[parts.length - 1]
}
return parts.length > index ? parts[index] : null;
}