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:
Compare the Triplets | Javascript | hackerrank.com07-05-2020 hackerrank.com |
Example for Conditional Operator in php16-04-2017 php Conditional Operator example |
How to use http-post request in node js14-03-2017 http-post module node js |
Email validation regular expression in javascript22-02-2017 email validation regex |
Send Mail in Node Js21-02-2017 node js mail npm module |