我知道之前已经问过,但我似乎无法找到答案,我想在嵌套数组中获取数据/对象。
schedule = await Schedule.findById({_id:'5b496ec3444152122c8d839e'})
console.log(schedule.datalayout.section.data.x)
如果要获取图像中的指定字段,则需要确定数组中的字段索引,如下所示:
console.log(schedule.datalayout.section[0].data[0].x)
而且,如果要获取数据数组中的所有x字段,则需要编写如下内容:
for(let singleData of schedule.datalayout.section[0].data){
console.log(singleData.x)
}
// for using 'of' keyword, your function must be a async function.