In this trick, we will know how you can get the query string parameters of the URL in JavaScript. We will URLSearchParams
API to get the query string from URL.
Let’s see with an example.
Suppose you have following URL.
https://example.com/service.php?show=all&price=0
In this URL, ?show=all&price=0
this part is a query string and you want to get the value of these parameters. Let’s see how you can get it.
Output
true
0
[“all”]
?show=all&price=0
?show=all&price=0&active=1
Hope you understand how to get query string parameters in javascript.
Being Tricky 😉