0
I am trying to group an array of objects that comes from the database in the following format:
[
{
'12312312': { 'first_name': 'David', 'id_question': 0, 'acertou': 1 },
'23423423': { 'first_name': 'Luis', 'id_question': 0, 'acertou': 1 },
'45645645': { 'first_name': 'José', 'id_question': 0, 'acertou': 1 }
},
{
'12312312': { 'first_name': 'David', 'id_question': 1, 'acertou': 1 },
'23423423': { 'first_name': 'Luis', 'id_question': 1, 'acertou': 0 },
'45645645': { 'first_name': 'José', 'id_question': 1, 'acertou': 1 }
},
{
'12312312': { 'first_name': 'David', 'id_question': 2, 'acertou': 1 },
'23423423': { 'first_name': 'Luis', 'id_question': 2, 'acertou': 1 },
'45645645': { 'first_name': 'José', 'id_question': 2, 'acertou': 0 }
}
]
I need to transform it to the following format:
[
{
first_name: "David",
resultados: [
{ "id_question": 0, "acertou": 1 },
{ "id_question": 1, "acertou": 1 },
{ "id_question": 2, "acertou": 1 }
]
},
{
first_name: "Luis",
resultados: [
{ "id_question": 0, "acertou": 1 },
{ "id_question": 1, "acertou": 0 },
{ "id_question": 2, "acertou": 1 }
]
},
{
first_name: "José",
resultados: [
{ "id_question": 0, "acertou": 1 },
{ "id_question": 1, "acertou": 1 },
{ "id_question": 2, "acertou": 0 }
]
}
]
Could someone please help me?
Thank you.
It is that I need to leave in that format to facilitate the work on the front.
– David Coelho