我有一个包含 143 个其他对象的数组的多级 JSON 对象。
在此对象上运行 console.log(obj) 会显示:
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"
等等......通过所有 143 个对象。但是,名称/值对 Mission_Name:"RST" 仅在前n 个对象中普遍存在。
例如,obj 43 包含:
43: Object
ActFTEs: 0.00
Actual: 10000
Bud_Month: "FY Total"
FY_CD: 2013
Mission_Name: "VAO"
我创建了以下函数,但这仍然返回与“Bud_Month”相关的名称/值对的全部 143 个值。
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;
}
这将返回:
["October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June"…]
有人对如何仅在包含 Mission_Name:"RST" 的名称/值对的对象中返回“Bud_Month”的值有任何建议吗?