每个正斜杠后都在JavaScript中拆分URL?
要拆分URL,请使用split()方法。toString()在此之前使用。让我们看一个例子
示例
var newURL="http://www.example.com/index.html/homePage/aboutus/";
console.log(newURL);
var splitURL=newURL.toString().split("/");
console.log(splitURL);上面,我们在split()函数中设置了正斜杠,因为我们需要在每个斜杠之后分割URL。
要运行上述程序,您需要使用以下命令-
node fileName.js.
输出结果
在这里,我的文件名为demo150.js。这将产生以下输出-
PS C:\Users\Amit\JavaScript-code> node demo150.js http://www.example.com/index.html/homePage/aboutus/[ 'http:', '', 'www.example.com', 'index.html', 'homePage', 'aboutus', '' ]
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短