How to remove last / value from url in javascript

array
javascript
last value

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:

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert

Filter for insert HTML in Angular Js

06-03-2017 filter show html angular js html

Filter for replace text in Angular Js

05-03-2017 filter replace angular js

Call a function every second or 5 seconds in javascript

22-02-2017 setinterval function calling

Email validation regular expression in javascript

22-02-2017 email validation regex