我知道这行代码应该执行的操作:
Data.AppointmentList[0].AppointmentList[0].OrderNo + ", ";
我必须导出所有
OrderNo
中存在的所有AppointmentList.AppointmentList
从此数组(不是正确的数组):
{
"AppointmentList": [
{
"AppointmentList": [
{
"OrderNo": 111,
"OrderNo": 222
}
]
}
}
JS:
$.each(Data, function(i, item){
for(i= 0; i < Object.keys(Data.AppointmentList.AppointmentList.OrderNo).length; i++) {
document.getElementById("divlist").innerHTML += Data.AppointmentList[0].AppointmentList[0].OrderNo + ", ";
}
})
需要以下输出:
111、222
最佳答案
let input = {
"AppointmentList": [
{"AppointmentList": [{"OrderNo": 1}, {"OrderNo": 2}]},
{"AppointmentList": [{"OrderNo": 3}]},
{"AppointmentList": [{"OrderNo": 4}, {"OrderNo": 5}, {"OrderNo": 6}]}
]
};
let orders = input.AppointmentList.flatMap(a => a.AppointmentList).map(a => a.OrderNo);
console.log(orders.join(', '));