I have below array of objects with each object having a projects attribute which further has its array of objects.
const data = [
{
"title": "Release",
"projects": [
{
"name": "Server",
"result": {
"success": 0,
"failure": 100
},
}
]
},
{
"title": "Payments",
"projects": [
{
"name": "Platform1",
"result": {
"success": 100,
"failure": 0
}
},
{
"name": "Platform2",
"result": {
"success": 50,
"failure": 50,
}
}
]
}
]
I wanted to iterate through it and get the result as follows. name is nothing but concatenation of title and name from above data.
const result = [
{
name: 'Release-Server',
success: 0,
failure: 100,
},
{
name: 'Payments-Platform1',
success: 100,
failure: 0,
},
{
name: 'Payments-Platform2',
success: 50,
failure: 5,
},
];
I have tried below ways but not able to figure out how to get exactly the result as shown above. can someone pls help on this.
data.forEach(prj => {
prj.projects.forEach((project) => {
// unable to get how to push these details into a new array of object
})
});
mapandflatMapmight be helpful here.