I have a URL of the form: https://www.example.com?tag[]=mountain&tag[]=hill&tag[]=pimple
Now I want to delete one of them, let's say tag[]=hill
. I know, I could use regex, but I'm using URLSearchParams
to add these, so I want to use that to remove them as well. Unfortunately the delete()
function deletes all pairs with the same key.
Is there a way to delete only a specific key-value pair?
You can also add it to the prototype of URLSearchParams so you can always use it easily in your code.
Now you can remove specific key-value pairs from URLSearchParams like this:
Do something like this: