I have a url like "https://abcd.com/qa2/index.html" How to get only qa2 in javascript?
var parts: string[] = location.pathname.split('/');
var paths:string[] = new Array();
parts.forEach(function(item){
if (item)
paths.push(item);
});
if(parts.length >=2)
{
console.log(parts[0]);
}
this is not giving me the result!
You can do:
window.location.pathname.split("/")[1]
Try this, location.pathname.split('/')?.[1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.