I have been trying today to flatten an object array. I cannot achieve what I need, I need to access to inner most element( 1st ) to the outer most element ( 4th ) here is a sample of the data there are some null values which might make it complex:
{
"School":"Arsenal 2011", //4th Element in new array
"Group":{
"Name":"Previous", //3rd Element in new array
"ParentGroup":{
"Name":"Arsenal", //2nd Element in new array
"ParentGroup":{
"Name":"USA", //1st Element in new array
"ParentGroup":null
}
}
},
"GroupDisplayText":null,
"Publisher":"Abbot",
"PublishedDate":"2011",
"PublishersWebsite":"http://google.com/USA/ADW%202011/Arsenal%202011.pdf"
},
{
"School":"New York 2000",
"Group":{
"Name":"New York",
"ParentGroup":{
"Name":"USA",
"ParentGroup":null
}
},
"GroupDisplayText":null,
"Publisher":"DoE",
"PublishedDate":"2000",
"PublishersWebsite":"http://google.com/USA/New York%202000%20Tables.pdf"
}
The output array I would like is:
array[0] = { "USA","Arsenal","Previous" } array[x] = for all the other data
How would I do this in Javascript?
I have added a plunker if it helps
https://plnkr.co/edit/LNlHArCob4Bix8VYHFwI?p=preview
Thanks