在Chrome扩展程序中,我有一个变量,它等于当前标签页的网址,例如currentUrl = tabs[0].url;
。它获得一个类似于http://www.example.com/folder-1/folder-2/folder-3/index.html
的网址。
我想从此URL获取/folder/-1
和/folder-3/
。>
尝试过currentPath = currentUrl.substring(0, currentUrl.lastIndexOf("/"));
,但通过这种方式,我只获得整个路径(http://www.example.com/folder1/folder2/folder3
)
在Chrome扩展程序中,我有一个变量,该变量等于当前标签页的url,例如currentUrl = tabs [0] .url;。它获得的网址如http://www.example.com/folder-1/folder-2/folder-3/index.html。我想...
const arr = "http://www.example.com/folder-1/folder-2/folder-3/index.html".split("/");
一种可行的方法
让我们测试更多情况: