Getting Query String Values in JavaScript in 2021

Safely access URLSearchParams

Johannes Baum
Better Programming
Published in
2 min readFeb 8, 2021

--

Code
Photo by Markus Spiske on Unsplash.

In the past, there wasn’t a simple solution to the simple problem of retrieving key-value pairs from the query string of a URL in plain JavaScript.

Let’s take a look at the following URL: http://example.com/search?someParam=someValue&anotherParam=anotherValue. The information that we are interested in…

--

--