I am using query string (https://www.npmjs.com/package/qs) to parse the params in the URL like so:
http://www.website.com/?filter="bags"&filter="shirts"
However, if I have no filter or just one filter it will return either a string or undefined:
http://www.website.com/?filter="bags" // returns 'bags'
http://www.website.com/ // returns undefined
The reason being I need to feed this result into functions / methods that use an array.
One solution I thought of is to sort of create condition depending on what it returns:
if (typeof query == 'string') {
query = [query];
} else if (query == undefined) {
query = [];
}
But this seems not optimal. Wondering if the result can just be an array all time instead.