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:

Functions in javascript

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

Detect AdBlock with JavaScript in my browser

30-07-2017 AdBlock javascript detect

How To Get Your Blogs Posts Using Blogger API

30-07-2017 blogger api json php

How to redirect one page to another page in php

20-03-2017 redirect php

Get random strings from given string In javascript

21-02-2017 javascript random string