Here is a demo array with a variable length (n).
[{
"name": "question",
"value": "this is the first question"
},
{
"name": "answer",
"value": "this is the first answer"
},
{
"name": "question",
"value": "this is the second question"
},
{
"name": "answer",
"value": "this is the second answer"
}
]
I am looking to combine two consecutive objects for the desired output.
[{"question":"This is the first question", "answer":"This is the first answer"}, {"question":"This is the second question", "answer":"This is the second answer"}]
Any ideas on how I can achieve this using JavaScript? I've been stuck on it for the past couple of days.