1 回答
TA贡献1805条经验 获得超10个赞
检查图片的长度,例如data[key].pictures.length > 0代替data[key].pictures !== []
let data = {
"01": {
"id" : "01",
"title" : "example1",
"size" : "100",
"pictures" : []
},
"02": {
"id" : "02",
"title" : "example2",
"size" : "0",
"pictures" : []
},
"03": {
"id" : "03",
"title" : "example3",
"size" : "300",
"pictures" : [
{ "pic_name1" : "example_pic1", "source" : "http://example.pic/1234" },
{ "pic_name2" : "example_pic2", "source" : "http://example.pic/4321" },
]
},
}
for (const key in data) {
if (data.hasOwnProperty(key)) {
if (data[key].size !== "0" && data[key].pictures.length>0){
console.log(data[key].size);
console.log(data[key].pictures[0].source);
}
}
}
添加回答
举报