无法显示深度嵌套的 JSON 对象。一直在查看各种 stackoverflow 帖子。感谢对这个新手问题的任何帮助。我希望它在运动员数组中显示运动员 JSONObject 的详细信息。它显示为 [Object]。
eventUnitResults: [ { is_team: true, athletes: [ [Object], [Object] ] },
{ is_team: true, athletes: [ [Object], [Object] ] } ]
const result = {}
let eventUnitResults = [];
let athletes = [];
for (i=0; i < 2; i++) {
const athlete = {};
athlete.athlete_name = 'Ram' + i;
athlete.athlete_gender = 'M'
athletes.push(athlete);
}
for (j=0;j < 2;j++) {
const nestedResult = {};
nestedResult.is_team = true;
if (athletes) {
nestedResult.athletes = athletes;
}
console.log('nestedResult:', nestedResult);
if (nestedResult) {
eventUnitResults.push(nestedResult);//TODO:
//eventUnitResults.push(JSON.stringify(nestedResult));//TODO:
}
}
console.log('eventUnitResults:', eventUnitResults);//<==== how can I get deeply nested values of athletes showing up properly here
if (eventUnitResults) {
result.event_unit_results = eventUnitResults;
}
console.log('result:', result)
TIA