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:

How to get id by using name attribute in javascript

20-03-2017 html id name javascript

How to get current date and time (yyyy-mm-dd H:i:s) using javascript

09-03-2017 javascript date time

Navigate to another page using java script

06-03-2017 javascript redirection navigation

Sample Validations in javascript

22-02-2017 validations javascript

Send Mail in Node Js

21-02-2017 node js mail npm module