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:
Detect AdBlock with JavaScript in my browser30-07-2017 AdBlock javascript detect |
How to insert bulk information into database in single query execution18-03-2017 insert sql bulk database |
Sanitization in java sript14-03-2017 sanitization java script |
Convert Time 24 hrs to 12 hrs format In javascript12-03-2017 date javascript 12hrs convert |
Using slice remove last two characters from given string07-03-2017 slice remove |