I'm starting a new project in React and my API returns me a JSON where the format is not what I want for meetings. I've tried to use destructuring and Object.entries. What I have:
{
"meetings": [
{
"room1": DC13,
"room2": AP47,
}
],
"teachers": [
{
"name: "Patrick",
"speciality":"Math"
},
...
],
"alumni": [
{
"firstName": "Joe",
"lastName":"Luis"
},
...
]
}
What I want:
{
"meetings": [
{
"name": room1,
"location": DC13,
},
{
"name": room2,
"location": AP47,
},
],
"teachers": [
{
"name: "Patrick",
"speciality":"Math"
},
...
],
"alumni": [
{
"firstName": "Joe",
"lastName":"Luis"
},
...
]
}
What I've tried but not working:
const data= {meetings, teachers, alumni}
const newData = Object.entries(meetings).reduce((acc,name,location])=>acc.concat({name,location}),[]))
and then use this newData for manipulation after.