I encountered an issue with one of the API responses, The response I received is as follows:
[
{type: "StateCountry", state: "AL", countries: [{type: "County", countyName: "US"}, {type: "County", countyName: "US"}, {type: "County", countyName: "US"}]},
{type: "StateCountry", state: "AL", countries: [{type: "County", countyName: "German"}, {type: "County", countyName: "German"}, {type: "County", countyName: "German"}]},
{type: "StateCountry", state: "AL", countries: [{type: "County", countyName: "Japan"}, {type: "County", countyName: "German"}, {type: "County", countyName: "German"}]},
]
This response consists of an array of objects, each containing country names in nested arrays. I am looking to extract all the county names into a single array, like this:
newNames = [US, German, Japan];
I attempted a solution but couldn't achieve the desired output. Can someone assist me with this? Thank you.
let newNames = this.selectedStateList.filter(item => item.countries.forEach(item => item.countries)).map(ele => ele.countries.forEach(item => item.countries))