Can not get property "userResponse" of undefined

I am tryna learn nativescript by building a travia game app. I have a questions json list like below:

var questionsList20 = {"questions" : [{"question":"Taxing a commodity at the production level decreases supply.","correctAnswer":"answerOne","answerOne":"True","answerTwo":"False","answerThree":"Uncertain","answerFour":"None of the above","userResponse":"","explanationTwo":"True","grade":""},{"question":"The circular flow depicts the alternative combination of goods and services an economy \tcan produce at a point in time.","correctAnswer":"answerTwo","answerOne":"True","answerTwo":"False","answerThree":"Uncertain","answerFour":"None of the above","userResponse":"","explanationTwo":"False","grade":""},{"question":"Demand is inelastic if elasticity of demand < 0.","correctAnswer":"answerTwo","answerOne":"True","answerTwo":"False","answerThree":"Uncertain","answerFour":"None of the above","userResponse":"","explanationTwo":"False","grade":""},{"question":"Elasticity of demand measures the percentage change in the quantity demand of a commodity as a result of a given percentage change in price.","correctAnswer":"answerTwo","answerOne":"True","answerTwo":"False","answerThree":"Uncertain","answerFour":"None of the above","userResponse":"","explanationTwo":"False","grade":""}]}

to get individual questions i am doing this:

questionViewModel.startNewGame = function () {


    for (var i = 0; i < questionViewModel.numberOfQuestions - 1; i++) {
        questionViewModel.test.questions[i].userResponse = "";
        questionViewModel.test.questions[i].grade = "";
    }
}

At first it works but later i get the error that cannot set property userResponse of undefined.

i don't know how to solve this. Please help.


ANSWERS:


You can try to initialize an empty question array and push each question like a Question object.

questionViewModel.startNewGame = function () {
    questionViewModel.test.questions = [];

    for (var i = 0; i < questionViewModel.numberOfQuestions; i++) {
        questionViewModel.test.questions.push({"userResponse": "", "grade": ""});
    }
}


 MORE:


 ? Page re-inits on navigating back to a page
 ? How to get the native control in RadSideDrawer with nativescript angular2?
 ? How can i use internal database from scratch
 ? Nativescript -Open SideDrawer on button click
 ? NativeScript Telerik-UI using ListViewStaggeredLayout for images in RadListView
 ? NativeScript Telerik-UI using ListViewStaggeredLayout for images in RadListView
 ? NativeScript Telerik-UI using ListViewStaggeredLayout for images in RadListView
 ? NativeScript/Angular2 Telerik-UI RadListView issue displaying images from remote urls
 ? Nativescript RadListView get scroll Y
 ? Telerik UI Nativescript - RadListView ripple effect