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 |
How to insert bulk information into database in single query execution18-03-2017 insert sql bulk database |
How to set or update or push the values into Object in javacript27-02-2017 javascript set update push object |
How to remove last / value from url in javascript27-02-2017 array javascript last value |
Get Unique values from array/object in javascript19-02-2017 javascript unique remove repeated values from array |