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 and download html to pdf without saving file

28-10-2018 node js convert html to pdf pdf download pdf without saving

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

Use java script file client side and server side at a time in node js

30-07-2017 node js include call javascript

How to convert html to pdf in Node js

12-03-2017 pdf convert html node js

Send Mail in Node Js

21-02-2017 node js mail npm module