I would like to change the url request while clicking on a link one of the element of an array. For example :
?foo[]=1&foo[]=2
to
?foo[]=1&foo[]=3
I use URLSearchParams with methods .getAll('foo[]') and then .set('foo[]', array)
Finally, I use jquery method param() to generate a correct url string (as I was not able to use URLSearchParams.toString() with an array -- the result is always foo[]=1&3).
This is working, but if I had other parameter in the request I would like to keep, it becomes complicated to regenerate the url.
For example :
?foo[]=1&foo[]=2&bar=3&bar[]=4&page=1
to
?foo[]=1&foo[]=3&bar=3&bar[]=4&page=1
I have many parameters, so I would like to avoid the rebuild the entire query object to pass to $.param(). So :
- Is there any option to get the whole array from
URLSearchParamswithout using any loop. - Is there any trick to use
URLSearchParams.toString()with arrays.