In this quick example i will discuss about how to get query string value in javascript. Many time we need this. We can do it many ways. But i am going to use URLSearchParam to get query string in javascript jquery. You can use it any javascript based application lake vue react angular or normal javascript or jquery.
Accessing the value of the query inside the browser in JavaScript, we have a special API called URLSearchParam, supported by all modern browsers. See the example that how we can use that:
const params = new URLSearchParams(window.location.search)
Suppose we have a url like that with those query string
https://test.com/hello?name=codecheef
Now we need the value of name parameter. How we can catch this query string from url? Have a look
We can check if a parameter was passed:
params.has('name')
We can get the value of a parameter:
params.get('name')
Hope it can help you.
#javascript #jquery