Return string without trailing slash

Tags: , ,

I have two variables:

site1 = "";  
site2 = "";  

I want to do something like this

function someFunction(site)
    // If the var has a trailing slash (like site2), 
    // remove it and return the site without the trailing slash
    return no_trailing_slash_url;

How do I do this?


Try this:

function someFunction(site)     
    return site.replace(//$/, "");

Source: stackoverflow