ArrayFormat Type Comma is producing the output of Array Format Repeat when the array length is 1
See original GitHub issueqs.stringify({ a: ['b'] }, { arrayFormat: 'comma' })
should return the a=b
.
But it is returning the repeat
type format - a%5B%5D=b ~ a[]=b
Below is the documentation and expected behaviour from readme
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'
Below is the screenshot for the same
Can anyone help me if this is an issue or Am I missing something?
Issue Analytics
- State:
- Created a year ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Stringify with `comma` format should add square brackets to ...
Hi. With new comma array format, stringify of array with single value will produce following result: const options = { arrayFormat: 'comma' } ......
Read more >How to correctly use axios params with arrays - Stack Overflow
YOUR_ARRAY.length - 1) params += '&'; }. And then make the request like so: ... In React I needed to use axios with...
Read more >Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >MATLAB repmat - Repeat copies of array - MathWorks
This MATLAB function returns an array containing n copies of A in the row and column dimensions.
Read more >Work with arrays | BigQuery - Google Cloud
In Google Standard SQL for BigQuery, an array is an ordered list consisting of zero or more values of the same data type....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
we run into the same issue with the new version.
not all APIs we are using are capable to handling query strings with brackets, they are expecting comma separated lists in all cases or no comma if it is only one value.
+1 for the additional option to toggle the “Arrayness” feature.
I have read the thread. But Shouldn’t it be configurable?
Can we have another option along with
arrayType
.preserveArrayness: true/false
Because there can be usecases like
One can use
qs
for stringifying it and may not be using it for parsing back again?In our case,
We stringify it and pass the query string to an external service and that service doesn’t use the
qs
module to parse it back?Any thoughts @ljharb