In this loop, I am facing an issue while trying to insert an array into another array. Here is the code snippet:
function convertFormToArray(form){
var temp={};
var question={};
var allQuestions=[];
for (i = 0; i < form.length; i++) {
// Below line is causing an issue
temp['question_id'] = form[i].name.substring(13)
temp['answer'] = form[i].value;
temp['id'] = 0;
question['question'] =temp;
allQuestions.push(question);
}
return allQuestions;
}
The problem here is that it returns the first result repeated multiple times.
Example of a returned value:
[
{'question': {'question_id': 4, 'answer': 'AA'...}},
{'question': {'question_id': 4, 'answer': 'AA'...}}
]
Can you identify the issue with this loop?