I have a url in this form http://www.example.com/data/45. How do I get the last element (45 in this example) using jQuery or JavaScript?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A very quick plain JavaScript method, assuming it’s the URL of the current page (in
window.location.href).split('/')obviously chops the URL up into an array, based on divisions by/. Since you only need the last part, it is probably the easiest method..pop()removes the last element from the array returned by.split()and returns it.