我有两个变量:
site1 = "www.somesite.com"; site2 = "www.somesite.com/";
我想做这样的事情
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; }
我该怎么做呢?
试试这个:
function someFunction(site) { return site.replace(/\/$/, ""); }