There are three arrays ,
var names = ["Increment","Decrement"]
var values1 = [1,2,3,4,5,6]
var values2 = [7,8,9,10,11]
Now i would like to construct a json like
{"names":[
{"Increment":"1,2,3,4,5,6"},
{"Decrement":"7,8,9,10,11"}
]}
There are three arrays ,
var names = ["Increment","Decrement"]
var values1 = [1,2,3,4,5,6]
var values2 = [7,8,9,10,11]
Now i would like to construct a json like
{"names":[
{"Increment":"1,2,3,4,5,6"},
{"Decrement":"7,8,9,10,11"}
]}
I suggest to change the data structure to a more compact style.
var names = ["Increment", "Decrement"],
values1 = [1, 2, 3, 4, 5, 6],
values2 = [7, 8, 9, 10, 11],
obj = {};
obj[names[0]] = values1;
obj[names[1]] = values2;
Result:
{
Increment: [1, 2, 3, 4, 5, 6],
Decrement: [7, 8, 9, 10, 11]
}
To generate a JSON, you may convert it with JSON.stringify() to a string.