Is there a standard way of passing an array through a query string?
To be clear, I have a query string with multiple values, one of which would be an array value.
Although there isn't a standard on the URL part, there is one standard for JavaScript. If you pass objects containing arrays to URLSearchParams
, and call toString()
on it, it will transform it into a comma separated list of items:
let data = {
str: 'abc',
arr: ['abc', 123]
}
new URLSearchParams(data).toString(); // ?str=abc&arr=abc,123