Skip to content

Instantly share code, notes, and snippets.

@flangofas
Created January 29, 2015 14:57
Show Gist options
  • Save flangofas/724ed26c0e0f6bd18c7f to your computer and use it in GitHub Desktop.
Save flangofas/724ed26c0e0f6bd18c7f to your computer and use it in GitHub Desktop.
Get last segment from URL
/**
* Get last segment from URL
* @note array.filter browser support: IE.9+, Firefox 1.5 +
* @return string URL last segment
*/
function getLastSegmentFromUrl() {
path = window.location.pathname;
segments = path.split('/');
//remove empty spaces
segments = segments.filter(function(item) {
if (item == "") {
return false;
}
return true;
});
if (segments.length !== 0) {
return segments[segments.length - 1];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment