Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

pasha1110 commented Mar 9, 2021

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