所以我有下面的代码,我正在尝试获取URL的商店名称部分,而不需要在两者之间添加乱七八糟的值。
let storeName=请求.url.split(“/”);console.log(“storeNamebefore:”,storeName);storeName=storeName.toString().replace(“%20”,“”);storeName=storeName.toString().replace(“%20”,“”);storeName=storeName.toString().replace(“,data,”,“”);console.log(“storeName after:”,storeName);
我试图删除URL中显示的%20符号和“,data”部分,但我很难将整个URL缩小为字符串“Sarah’s Day Salon”,并将该值赋给storeName变量。现在,我可以将字符串缩小到下面,但字符串的开头有一个很大的间距问题,我也不确定这是否是从URL捕获“Sarah’s Day Salon”部分的最有效方法。我想知道是否有人对我如何将URL缩小到只包含商店名称有任何建议?
打印上面代码中的值:
storeName before:['','data',“Sarah的%20Day%20沙龙”]storeName after:萨拉日沙龙