如果网址为https://example.com/web/fundamentals/course/dashboard
我可以将它拆分为数组。
const url = "example.com/web/fundamentals/course/dashboard"
path = url.split("/");
const [head1,head2, ...rest] = path;
console.log(head1);
console.log(head2);
console.log(rest);

但是如何将其余部分作为字符串fundamentals/course/dashboard
,而不是没有" /"在里面。
答案 0 :(得分:2)
答案 1 :(得分:1)
const url = "example.com/web/fundamentals/course/dashboard"
path = url.split("/");
const [head1,head2, ...rest] = path;
console.log(head1);
console.log(head2);
console.log(rest.join('/'));