How to easily manipulate URL search parameters in JavaScript
Back from the dead with another article
Hey there!
It’s been a while since my last article, but I’m back from the dead (again) 😊
Since my last email, quite a few people joined the newsletter (646 as of writing this 🎉). I’m curious to get to know you as well. So, if you like, feel free to respond to this email to say hi and tell me something about yourself; are you working on something interesting? What are you currently learning?
How to easily manipulate URL search parameters in JavaScript
I came across this issue once again at work: How do I (easily) create a search query based on an object?
Manipulating URLs is a common task when working on web applications, and yet, I somehow always forget how to do it.
The solution is quite simple: JavaScript’s “URLSearchParams” API offers most of the functionality needed.
As with most things in programming, though, this solution comes with its own set of issues. It turns out that arrays and objects aren’t supported by that API, and even worse, there are infinite possible implementations as there’s no standard for defining them in URLs.
In the article, I explain what you need to know about manipulating URL search parameters with the JavaScript API. In the end, I offer one solution for parsing arrays, which you may copy and adapt for your specific URL-array-implementation.
I hope this article proves useful to some of you!
You’ll hear from me again in 2 weeks or so when I finish my next article.
Felix