I am building a questionnaire and the questions can have multiple answers and I need to build an array of the question and answers such as:
{
question: 'question',
answer: {id: 1, answers: 'answer 1'},
{id: 2, answer: 'answer 2'}
}
I need to show a summary of the questions and the answers that the user chose.
For example: Question: Which of these states have you lived in? answers: Alabama, Alaska, New Jersey, Rhode Island.
The resulting object could be:
{
question: 'Which of these states have you lived in?',
answer: {id: 1, answer: 'Alaska'},
{id: 3, answer: 'Rhode Island'}
}
How do I go about dynamically adding the answers while only having the question show up once?
I tried:
var questionAnswerObject = [];
angular.forEach(answersObject, function(value, key){
questionAnswerObject.push({
question: question.question,
answer: value.answer
});
});
But of course it shows the question twice.
answersObjectandquestionlook like?