我有一个数组,questionsArray,我需要在该数组中的每个问题中做一些事情。第一次迭代有效,但除此之外,它说它无法读取 null 的属性 x。这是为什么?- 这是遍历数组的代码:
var insertion = new Promise(async (resolve, reject) => {
for(const question of questionsArray){
await db.query('INSERT INTO `ml-questions-data` (`text`, `status`, `question_id`, `answer_text`, `answer_status`, `answer_date`, `item_id`, `seller_id`, `created`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);',
[question.text, question.status, question.id, question.answer.text, question.answer.status, question.answer.date_created, question.item_id, question.seller_id, question.date_created], (erro)=>{
if(erro){
reject(erro)
}
else{
console.log('array iteration! db insertion')
}
})
}
resolve()
});
-这是questionsArray数据:
[
{
"date_created": "2019-09-30T03:18:08.000-04:00",
"item_id": "MLB1329418290",
"seller_id": 158369990,
"status": "ANSWERED",
"text": "olá, gostaria de entender como funciona isso?",
"id": 6553335409,
"deleted_from_listing": false,
"hold": false,
"answer": {
"text": "pois bem, vamos adicionar um texto de resposta no json",
"status": "ACTIVE",
"date_created": "2019-09-30T03:24:52.120-04:00"
},
"from": {
"id": 444188609,
"answered_questions": 2
}
},
{
"date_created": "2019-09-30T03:22:21.000-04:00",
"item_id": "MLB1329418290",
"seller_id": 158369990,
"status": "BANNED",
"id": 6553335807,
"deleted_from_listing": false,
"hold": false,
"answer": null,
"from": {
"id": 444188609,
"answered_questions": 2
}
},
the array goes on.....
]
慕村225694
神不在的星期二
for循环应该每次都会全部迭代完才对,为什么f1()的结果一定是输出的是i=1的结果呢
迭代变量foreach
关于迭代次数
调用for函数时对迭代内部数据没有任何要求吗?
相关分类