-2

For example, let's say http://www.google.com/Stack/overflow

In this above example, overflow is the last character. I need to fetch that overflow character

Please help me to achieve this

window.location.href
4
  • window.location.href[window.location.href.length -1] :P Commented Dec 13, 2017 at 4:26
  • Last character, or last path segment? Commented Dec 13, 2017 at 4:26
  • @varun this will throw the last letter as google.com/varun o/p as "n" rite i nee varun the whole word Commented Dec 13, 2017 at 4:28
  • 2
    @Shyam Then your question is wrong mate! A character is a single unit! Commented Dec 13, 2017 at 4:29

1 Answer 1

2

Try this:

window.location.href.split('/').pop();

This splits the URL and returns the last element of that array using .pop().

Sign up to request clarification or add additional context in comments.

1 Comment

great sort and sweet...+1 from me

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.