I have many questions and different answers (which I build dynamically, so the number of records and different answers can vary):
var qaArray = [
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer C"},
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer C"},
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
]
I need a function to create another array object from this that will contain the “answer” and “count”, in which case it will be:
[
{ answer: "Answer A", count: 3 },
{ answer: "Answer B", count: 4 },
{ answer: "Answer C", count: 2 },
]
Is there an easy way to do this without direct contours?
source
share