How to remove last / value from url in javascript

27-02-2017 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('/');
    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:

How to get id by using name attribute in javascript
20-03-2017 html id name javascript
How to change background color and color to the text using javascript
27-02-2017 css javascript colors
Call a function every second or 5 seconds in javascript
22-02-2017 setinterval function calling
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