When an array has more than 21 items, it is parsed from a url string into an object, instead of array
See original GitHub issueFollowing an error that array.includes is not a function, it turns out that when an array which is longer than 21 items is translated into a url query string (using qs.stringify), and than the url string is parsed (using qs.parse) it returns an object, not an array. This can obviously cause issues when you expect an array and it’s methods.
console.log( typeof(qs.parse(qs.stringify({activities:[....array 20 items long]})) ) // Array
console.log( typeof(qs.parse(qs.stringify({activities:[....array 22 items long]})) ) // Object
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to convert URL parameters to a JavaScript object?
This is a BAD solution when you have an array field within your query params. In a case where you have ids=1&ids=2, you'd...
Read more >JavaScript Split – How to Split a String into an Array in JS
The split() method splits (divides) a string into two or more substrings depending on a splitter (or divider). The splitter can be a...
Read more >eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.
Read more >URL | Node.js v19.3.0 Documentation
In accordance with browser conventions, all properties of URL objects are implemented as getters and setters on the class prototype, rather than as...
Read more >http_build_query - Manual - PHP
If data is an array, it may be a simple one-dimensional structure, or an array of arrays (which in turn may contain other...
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
@ljharb — I can give some more info here.
@samicodesit is hitting the same issue that I am. Although
arrayLimit
is an option forqs.parse
, it is not an option forqs.stringify
. So, when we attempt to stringify an array with more than 20 items in the array, the function appears to usearrayFormat: 'indices'
instead of the desired ``arrayFormat: ‘brackets’`.We just need an option to specify an
arrayLimit
in thestringify
method.Also, THANK YOU for this package. We are heavily using
qs
in Payload CMS and have just run into this same need.UPDATE:
I just found that this was actually not caused by the
qs.stringify
method on our frontend app—instead, it was caused by theqs-middleware
package that we used on the backend, which was responsible for parsing incoming query strings. I needed to set thearrayLimit
in that middleware, in order to parse large arrays. I thought it was the frontendstringify
but it was actually the backend.@samicodesit you might be having the same issue?
This is the
arrayLimit
option, which is documented in the readme.