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 upload file by using request module18-03-2017 request module node js |
Navigate to another page using java script06-03-2017 javascript redirection navigation |
How to get drop down value when drop down change using javascript27-02-2017 onchange events dropdown javascript functions |
How to set or update or push the values into Object in javacript27-02-2017 javascript set update push object |
Get Unique values from array/object in javascript19-02-2017 javascript unique remove repeated values from array |