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:

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

How To Get Your Blogs Posts Using Blogger API

30-07-2017 blogger api json php

Remove last two characters from given string

06-03-2017 substring javascript remove

Filter for change Date format (MM-dd-yyyy) in Angular Js

05-03-2017 mm-dd-yyyy date formats angular js

How to get drop down value when drop down change using javascript

27-02-2017 onchange events dropdown javascript functions