这是一项使用jService api创建“危险游戏”的任务;我正在遍历console.logging进行自我检查,但是当我在下面记录答案时,它的打印内容未定义,而问题和标题将打印到控制台而没有任何问题。我想念什么?
async function getCategory() {
for (let catID of catIDs) {
// console.log(catID);
const response = await axios.get('http://jservice.io/api/clues?category=' + catID);
// console.log(response);
let clueArray = [
{
question: response.data[0].question
},
{
answer: response.data[0].answer
}
];
let clue = {
title : response.data[0].category.title,
cluesArray: clueArray
}
console.log(clue.title);
console.log(clue.cluesArray[0].question);
console.log(clue.cluesArray[0].answer); //this line logs undefined
}
return clue;
}
答案 0 :(得分:0)
let clueArray = [
{
question: response.data[0].question
},
{
answer: response.data[0].answer
}
];
应该是
let clueArray = [
{
question: response.data[0].question,
answer: response.data[0].answer
}
];