我有一個數(shù)組,questionsArray,我需要在該數(shù)組中的每個問題中做一些事情。第一次迭代有效,但除此之外,它說它無法讀取 null 的屬性 x。這是為什么?- 這是遍歷數(shù)組的代碼: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數(shù)據(jù):[ { "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.....]
在“for...of”循環(huán)中無法讀取超出第一次迭代的內(nèi)容/迭代為空
手掌心
2021-11-04 15:35:56