I have an issue with flattening array.
Given that the structure is following
{
"name": "Somename",
"property": [
[
{
"prop": "someprop",
"other": "someother"
},
{
"prop": "someprop",
"other": "someother"
}
],
[
{
"prop": "someprop",
"other": "someother"
},
{
"prop": "someprop",
"other": "someother"
},
{
"prop": "someprop",
"other": "someother"
},
{
"prop": "someprop",
"other": "someother"
}
],
[
{
"prop": "someprop",
"other": "someother"
}
]
]
}
Or maybe better illustrated with this pic
How can I flatten matches into single array of objects or actually have flat structure where all nested items are in single array or object ?
I have managed to get so far by wrangling data but seem stuck at this I can use pretty much any library or tool and latest JS features.
I have tried mapping over values , reducing it using lodash deepMerge but cant seem to accomplish what I want.
Input:
const data = [
{
"sport": "Handball",
"matches": [
[
{
"home": "Izmir BSB SK (Youth) (Wom)",
"away": "Bursa Osmangazi (Youth) (Wom)",
"ID": "3092996854"
}
],
[
{
"home": "Al Muheet U21",
"away": "Al Mohmel U21",
"ID": "3092999932"
}
]
]
},
{
"sport": "Volleyball",
"matches": [
[
{
"home": "Ji-Hee Choi/Michika Ozeki",
"away": "Panji Ahmad Maulana",
"ID": "3093062401"
},
{
"home": "Ryazan (Wom)",
"away": "Angara Irkutsk (Wom)",
"ID": "3093062393"
}
],
[
{
"home": "CF Carthage (Wom)",
"away": "Winner - Broughton Excels",
"ID": "3093721823"
}
],
[
{
"home": "Ankara Yildirim Beyazit Universitesi (Wom)",
"away": "Saglik Bilimleri Universitesi (Wom)",
"ID": "3093058567"
}
]
]
}
]
Expected output of each matches prop:
{
"sport": "Handball",
"matches": [
{home: '...', other: '...', id: '...'},
{home: '...', other: '...', id: '...'},
{home: '...', other: '...', id: '...'},
{home: '...', other: '...', id: '...'},
]
}