gpt4 book ai didi

javascript - 返回不带斜杠的字符串

转载 作者:IT老高 更新时间:2023-10-28 13:18:10 25 4
gpt4 key购买 nike

我有两个变量:

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(/\/$/, "");
}

关于javascript - 返回不带斜杠的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6680825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com