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:
Simple Array Sum | Javascript | hackerrank.com07-05-2020 hackerrank.com javascript arrays array sum |
Functions in javascript25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions. |
How to get current date and time (yyyy-mm-dd H:i:s) using javascript09-03-2017 javascript date time |
Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js05-03-2017 mm-dd-yyyy HH:MM date formats angular js |
Email validation regular expression in javascript22-02-2017 email validation regex |