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.

How to search text in string using php ?

29-10-2017 php search string search

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to get id by using name attribute in javascript

20-03-2017 html id name javascript

Get previous date from given date in javascript

06-03-2017 date javascript previous date