Saturday, 24 August 2013

Adding JSON elements to two dimensional array

Adding JSON elements to two dimensional array

Good Day,
I have this JSON object that i want to push and change the two values in
to another array
var line4 = [
{"viewed":2, "sumDate":1377129600000, "redeemed" : 8},
{"viewed":12, "sumDate":1377129600000, "redeemed" : 3},
{"viewed":18, "sumDate":1377129600000, "redeemed" : 13}
];
i want the new line4 to be like this format
line4 = [["2008-06-30", 2], ["2008-7-14", 12, ["2008-7-28", 18]]
i cant seem to format it correctly to my array
$(line4).each(function (index, value) {
console.log("value: " + value);
$(value).map(function(){
d = new Date(parseInt(this.sumDate));
this.sumDate = (1 + d.getMonth()) + '/'+ d.getDate() + '/' +
d.getFullYear().toString().slice(-2);
console.log("sumdate : " +this.sumDate);
console.log("viewed : " +this.viewed);
line5.push([this.sumDate, this.viewed]);
});
});
but im getting
line4 : 8/21/13,2,8/21/13,12,8/21/13,18

No comments:

Post a Comment