How to remove last / value from url in 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('/');
    return( the_arr.join('/') );
var res = RemoveLastDirectoryPartOf(window.location.href);

Try this simple method using lastIndexOf() and slice()

url = window.location.href;
url = url.slice(0, url.lastIndexOf('/'));
url = url.slice(0, url.lastIndexOf('/'));







You might also like:

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 insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

How to upload file by using request module

18-03-2017 request module node js

Get random strings from given string In javascript

21-02-2017 javascript random string

Send Mail in Node Js

21-02-2017 node js mail npm module