admin管理员组文章数量:1331538
I am using querySelector from and I want to output an array as as ma separated string.
I start with a URL search string and then parse it using qs
I then tried the qs
stringify
method to return the formatted string.
const sUrl = 'a=1&b=1&c=1&c=2&c=3';
const oData = qs.parse(sUrl);
// oData returns:
{
a: 1,
b: 1,
c: ['1', '2', '3']
}
const sData = qs.stringify(oData);
// sUrl returns: 'a=1&b=1&c%5B0%5D=1&c%5B1%5D=2&c%5B2%5D=3'
I want the output to be:
a=1&b=1&c=1,2,3
I am using querySelector from https://www.npmjs./package/qs and I want to output an array as as ma separated string.
I start with a URL search string and then parse it using qs
I then tried the qs
stringify
method to return the formatted string.
const sUrl = 'a=1&b=1&c=1&c=2&c=3';
const oData = qs.parse(sUrl);
// oData returns:
{
a: 1,
b: 1,
c: ['1', '2', '3']
}
const sData = qs.stringify(oData);
// sUrl returns: 'a=1&b=1&c%5B0%5D=1&c%5B1%5D=2&c%5B2%5D=3'
I want the output to be:
a=1&b=1&c=1,2,3
-
I found a second argument
arrayFormat: ma
but even that did not work. I expect because it's an array inside an object. – UXCODA Commented May 10, 2019 at 0:38
1 Answer
Reset to default 8qs
has an option to specify the array format, so to get the desired output, you can use:
qs.stringify(oData, { arrayFormat: 'ma', encode: false })
encode: false
is also used so the mas aren't URL encoded.
With an input of:
{
a: 1,
b: 1,
c: ['1', '2', '3']
}
It will return:
a=1&b=1&c=1,2,3
本文标签: javascriptOutput array as comma separated with querySelectorStack Overflow
版权声明:本文标题:javascript - Output array as comma separated with querySelector - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742282317a2446320.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论