How to parse URL in TypeScript

1 Answer

0 votes
const url: string = "https://www.collectivesolver.com/search?q=array";
 
const urlobj: URL = new URL(url);
 
console.log(urlobj.hostname );
console.log(urlobj.href);
console.log(urlobj.origin);
console.log(urlobj.pathname);
console.log(urlobj.protocol);
console.log(urlobj.search);
 
 
 
/*
run:
 
"www.collectivesolver.com" 
"https://www.collectivesolver.com/search?q=array" 
"https://www.collectivesolver.com" 
"/search" 
"https:" 
"?q=array" 
 
*/

 



answered Jan 31, 2025 by avibootz

Related questions

2 answers 152 views
3 answers 162 views
1 answer 156 views
1 answer 66 views
1 answer 150 views
1 answer 128 views
...