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:

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

30-07-2017 node js include call javascript

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

Get next date from given date in javascript

06-03-2017 date javascript next date

Get random strings from given string In javascript

21-02-2017 javascript random string