Get in touch

Send an email to:
Or find me online at: Github, Twitter/X

Get query params from URL

The URLSearchParams object can be used to easily work with the query parameters of a website URL. Create a new URL object by passing the document.location to the constructor. This newly created object contains a searchParams property which gives access to the query parameters.

const { searchParams } = new URL(document.location)

searchParams.get('id') // foo
searchParams.has('age') // true
searchParams.forEach(param => console.log(param)) // foo, 94