How do you output the data from an object with dynamic properties. I have got an array of objects from an api call. This array contains one object named languages, they key value pair of this object are dynamic, so how to out put the data? I can output the name of the countries, capitals and flags but languages object which has dynamic properties I am not able to output it.
`
export default class CountryList extends React.Component {
state = {
countries: []
}
componentDidMount() {
axios.get(`https://restcountries.com/v3.1/all`)
.then(res => {
const countries = res.data;
console.log(countries)
this.setState({ countries });
})
}
render() {
this.state.countries.sort((a, b) => a.name.common > b.name.common ? 1 : -1,)
return (
< div >
{
this.state.countries.map((item, index) => (
<p key={index}> {item.name.common} {item.flag} {item.capital} {item.name.official} </p>
))
}
</ div >
)
}
}
`
I tried but this didn't work to show the data from languages for each country
this.state.countries.map((item, index) => {
for (const iterator in item.languages) {
console.log(iterator, item.languages[iterator]);
}
});