My dilemma lies in extracting and storing specific data from a JSON object into an array. I am struggling to organize the information as desired within the array structure outlined below:
Array = [0]['start'] = 'Date1', [0]['end'] = 'Date2', [0]['name'] = 'NameN'
With the index of the array being represented by n
As you can envision, there will be multiple entries in this array that can be accessed based on their respective indexes.
var array = new Array();
var label;
data = JSON.parse(data);
$.each(data.rows, function(i, row) {
$.each(row.c, function(j, item) {
if(j == 0){
label = 'start';
}
if(j == 1){
label = 'end';
}
if(j == 2){
label = 'name';
}
if(j == 0 || j == 1 || j == 2){
array[i]["test"] = item.v;
//console.log('array['+i+']['+label+'] = '+ item.v);
}
//console.log(item.v);
});
});
I'm seeking guidance on achieving this functionality in JavaScript. Thank you!
Edit: Initially, my JSON looked like this
{"cols":[{"id":"","label":"start","pattern":"","type":"datetime"},{"id":"","label":"end","pattern":"","type":"datetime"},{"id":"","label":"content","pattern":"","type":"string"}],"rows":[{"c":[{"v":"Date(2014, 3, 25)","f":null},{"v":"Date(2014, 4, 2)","f":null},{"v":"Subgoal A","f":null}]},{"c":[{"v":"Date(2014, 4, 2)","f":null},{"v":"Date(2014, 4, 9)","f":null},{"v":"Subgoal B","f":null}]}],"p":null}