Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last value in URL path string

Given an href like:

http://localhost:8888/#!/path/somevalue/needthis

How can I get the last value in the path string (aka: "needthis")?

I tried using window.location.pathname, which gives "/".

I also tried using Angular's $location, which doesn't provide the last value.

like image 641
user3871 Avatar asked Jun 25 '15 17:06

user3871


2 Answers

you can try this:

s="http://localhost:8888/#!/path/somevalue/needthis"
var final = s.substr(s.lastIndexOf('/') + 1);
alert(final)
like image 151
David Untama Avatar answered Oct 26 '22 12:10

David Untama


window.location.pathname.split("/").pop()

like image 43
Himanshu Tanwar Avatar answered Oct 26 '22 11:10

Himanshu Tanwar