I am currently dealing with a multi-level JSON object that includes an array of 143 other objects. When I run console.log(obj) on this object, the following output is displayed:
0: Object
ActFTEs: 0.00
Actual: 11111
Bud_Month: "October"
FY_CD: 2013
Mission_Name: "RST"
__proto__: Object
1: Object
ActFTEs: 0.00
Actual: 10000
Bud_Month: "FY Total"
FY_CD: 2013
Mission_Name: "RST"
and so on for all 143 objects. However, the name/value pair Mission_Name:"RST" only appears in the first n objects.
For example, object 43 looks like this:
43: Object
ActFTEs: 0.00
Actual: 10000
Bud_Month: "FY Total"
FY_CD: 2013
Mission_Name: "VAO"
I have created a function to filter out "Bud_Month" values based on the existence of Mission_Name:"RST", but it seems to be returning all 143 values instead of just those associated with Mission_Name:"RST". Here is the function:
function get_dataArray() {
var arr = [];
var i= 0;
for (i=0;i<jsonobj.row.length;i++) {
if (jsonobj.row[i][name]="RST") {
arr[i] = jsonobj.row[i]["Bud_Month"];
}
}
console.log(arr);
return arr;
}
When running this function, the output consists of all 143 "Bud_Month" values as follows:
["October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", and so on...]
If anyone has any suggestions on how to retrieve only the "Bud_Month" values from objects that contain the name/value pair of Mission_Name:"RST", I would greatly appreciate it!