I have a JavaScript object in the format
{
"header": {
"dataFields": ["number", "name", "quantity", "id", "from"]
},
"data": [
"20|sam|12|2|2012-06-29T00:00Z|",
"18|peter|231|12|",
]
}
I am trying to get it in to this format:
[{"number" : "20", "name":"sam", "quantity" : "12", "id":"2"},
{"number" : "18", "name":"peter", "quantity": "231", "id" 12"}]
I dont want the field "from in the output array.. what could be the best way to acheive it??
var l={};
for ( var key in responseData.positions[i]){
l.name=key;
for(var k=0; k<responseData.positions.length;k++){
for ( var key in responseData.positions[k]) {
l.value= responseData.positions[k][key] ;
}
}
mainArray.push(l);
responseDatacontains the object, but what ispositions? Why aren't you usingresponseData.headerorresponseData.data? Where are you settingi? And your braces don't match, you have 3 opens and only 2 closes.