javascript 中的第一个数组元素未定义

undefined on first array element in javascript

我正在 JavaScript 中尝试一个简单的测验应用程序。我有问题对象数组,当我遍历数组并打印出第一个问题时未定义的问题,但第二个问题将问题打印到 console.log。任何人都知道这里发生了什么。

谢谢。

var questions = 
    [
      
      {
        questions: "What color is of milk?",
        choices: ["White", "Blue", "Brown", "Red"],
        answer: 0
      },
      
      {
        question: "What is Tallest Building in the world?",
        choices: ["Eifle Tower","Burg Khalifa", "Shenghai Tower" ],
        answer: 1
      }
    ];


  for ( var i = 0; i < questions.length; i++ ) {
     question = questions[i].question;
     choices = questions[i].choices;
     answer = questions[i].answer;
    
    console.log ( question );
    console.log ( choices );
    console.log ( answer );
  
  }

不应该 questions: "What color is of milk?",question: "What color is of milk?",

这很好用。

var questions = 
    [

      {
        question: "What color is of milk?",
        choices: ["White", "Blue", "Brown", "Red"],
        answer: 0
      },

      {
        question: "What is Tallest Building in the world?",
        choices: ["Eifle Tower","Burg Khalifa", "Shenghai Tower" ],
        answer: 1
      }
    ];


  for ( var i = 0; i < questions.length; i++ ) {
     question = questions[i].question;
     choices = questions[i].choices;
     answer = questions[i].answer;

    console.log ( question );
    console.log ( choices );
    console.log ( answer );

  }