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 368 views
368 views asked Feb 27, 2020 by avibootz
3 answers 538 views
1 answer 195 views
3 answers 325 views
3 answers 420 views
1 answer 303 views
...