Here we are some different types to get last value from array
function RemoveLastDirectoryPartOf(the_url) { var the_arr = the_url.split('/'); the_arr.pop(); return( the_arr.join('/') ); } var res = RemoveLastDirectoryPartOf(window.location.href); alert(res);
Try this simple method using lastIndexOf() and slice()
url = window.location.href; url = url.slice(0, url.lastIndexOf('/')); alert(url); url = url.slice(0, url.lastIndexOf('/')); alert(url);
You might also like:
How to submit form using javascript or jquery.16-04-2017 javascript jquery submit form |
How to redirect one page to another page in php20-03-2017 redirect php |
Get next date from given date in javascript06-03-2017 date javascript next date |
Filter for replace text in Angular Js05-03-2017 filter replace angular js |
How to set or update or push the values into Object in javacript27-02-2017 javascript set update push object |