I have 2 objects OldAnswer and NewAnswer. I am trying to convert array of OldAnswer objects to array of NewAnswer objects.
export class AnswerComponent implements OnInit {
answers: OldAnswer[] = [/* some data  */];
newanswers: NewAnswer[];
constructor() {
    this.answers.forEach(function (answer) {
        answer.answers.forEach(function (a){
            for (var key in a) {
                text = // some logic"";     
            }
            // exception in below line
        this.newanswers.push({id: answer.observationId,answer: text});
        });
    });
    }
}
but I am getting "Can't call newanswers on undefined". Why is this object undefined here and not while accessing answers?

