Skip to content

Instantly share code, notes, and snippets.

@jserrao
Created July 27, 2016 14:41
Show Gist options
  • Save jserrao/40f7b18ea91f42af4687ab30ceaee004 to your computer and use it in GitHub Desktop.
Save jserrao/40f7b18ea91f42af4687ab30ceaee004 to your computer and use it in GitHub Desktop.
Get Last Segment of a URL in Javascript
var pageURL = window.location.href;
var lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
console.log(lastURLSegment);
@mady143
Copy link

mady143 commented Feb 28, 2019

hi
for suppose in my url i am having like +,=,/,<,> like this then how can i get the last segment can you explain me

Thanks in advance
Happy codding....

@pasha1110
Copy link

Thank you bro, this tutorial saved my time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment