How to parse query string in JavaScript

2 Answers

0 votes
const url = "https://www.seek4info.com/search.php?query=web+hosting";

const urlobj = new URL(url);

console.log(urlobj.searchParams.get('query'));

 



/*
run:

"web hosting"

*/

 



answered May 22, 2021 by avibootz
0 votes
const url = "https://www.seek4info.com/search.php?query=web%20hosting&order=rand";

const urlobj = new URL(url);

console.log(urlobj.searchParams.get('query'));
console.log(urlobj.searchParams.get('order'));
 



/*
run:

"web hosting"
"rand"

*/

 



answered May 22, 2021 by avibootz

Related questions

2 answers 228 views
228 views asked Feb 27, 2020 by avibootz
3 answers 381 views
1 answer 110 views
3 answers 177 views
3 answers 264 views
1 answer 211 views
...