есть два возможных простых решения для выгрузки массива в виде строки. В зависимости от используемой среды:
… в современных браузерах используйте JSON:
JSON.stringify(filters);
// returns this
"{"dvals":[{"brand":"1","count":"1"},{"brand":"2","count":"2"},{"brand":"3","count":"3"}]}"
… с чем-то вроде node.js вы можете использовать console.info ()
console.info(filters);
// will output:
{ dvals:
[ { brand: '1', count: '1' },
{ brand: '2', count: '2' },
{ brand: '3', count: '3' } ] }
Редактировать:
JSON.stringify поставляется с еще двумя необязательными параметрами. Третий параметр «пробелы» включает красивую печать:
JSON.stringify(
obj, // the object to stringify
replacer, // a function or array transforming the result
spaces // prettyprint indentation spaces
)
пример:
JSON.stringify(filters, null, " ");
// returns this
"{
"dvals": [
{
"brand": "1",
"count": "1"
},
{
"brand": "2",
"count": "2"
},
{
"brand": "3",
"count": "3"
}
]
}"