Ive been struggling for hours to construct a json array but with no success whatsoever. For someone who has experience in json would be a piece of a cake for him.
So i want to construct a json array like this:
{
"M" : [ {id:"58893_1_M", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"L" : [ {id:"58893_1_L", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"XL" : [ {id:"58893_1_XL", value:"Ontario", imageFile:"58893_1.jpg"} ]
}
Here is the code:
var totalObjects = new Array();
for (i = 0; i < roomQuotes.length; i++) {
var selectedClothe = {
index: []
};
var clotheId = some value;
var clotheQuantity = some value;
var clotheImage =some value;
selectedClothe.index.push({ "id": clotheId , "value": clotheQuantity , "imageFile": clotheImage });
totalObjects.push(selectedClothe);
}
But instead i have this output
{
"index" : [ {id:"58893_1_M", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"index" : [ {id:"58893_1_L", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"index" : [ {id:"58893_1_XL", value:"Ontario", imageFile:"58893_1.jpg"} ]
}
How can i put a value in index variable?
Thanks for any help