I have this nested objects:
"State Names": {
"State Cities": {
"Los Angeles": {
"about": "story",
"zip": "91721"
},
}
}
and I was trying to make it look like this:
state: {
city: [
"name": "Los Angeles",
"about": "story",
"zip": "91721"
]
}
I've tried below code:
var o = {
"State Names": {
"State Cities": {
"Los Angeles": {
"about": "story",
"zip": "91721"
},
}
}
}
var v = o["State Names"];
var z = v["State Cities"];
const result = Object.keys(z).map(i => z[i]);
const state = {
city: [...result]
}
this.setState({
state
})
But my result doesn't showing city names, only showing about and zip. How do I include object key name into array as property during the map function?