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.
you can try this:
s="http://localhost:8888/#!/path/somevalue/needthis"
var final = s.substr(s.lastIndexOf('/') + 1);
alert(final)
window.location.pathname.split("/").pop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With