Tip #43[URLSearchParams class]

The built-in URLSearchParams class allows you to easily manage search params for a given url.

If you have an URL instance, you can easily obtain a map-like object using the searchParams property:

You can easily get a value of a given search parameter without the need to make use of regular expressions or manually converting a search query into a map:

In addition, when you set a search parameter, it gets properly encoded:

You can also explicitly create an instance of the URLSearchParams class and pass a search query (? sign is optional) to the constructor:

Live example:

If you like the tip, please give me some applause 👏

--

--