I am having a few issues formatting data in the way I require it. At the moment, I have an empty function
populateAddresses(data) {
console.log(JSON.stringify(data))
}
This outputs the full data which takes the following format
{
"county": "WEST MIDLANDS",
"town": "SOLIHULL",
"streets": [
{
"name": "MARSLAND ROAD",
"numbers": [
{
"buildingNumberOrName": "1",
"buildingName": "",
"subBuildingName": "",
"buildingNumber": "1"
},
{
"buildingNumberOrName": "3",
"buildingName": "",
"subBuildingName": "",
"buildingNumber": "3"
}
]
}
],
"postcode": "B92 7BU"
}
So it is basically the addresses for a postcode. What I am trying to do is create an array of complete addresses. So for the above example, my array would be something like this
["1 MARSLAND ROAD, SOLIHULL, WEST MIDLANDS, B92 7BU", "3 MARSLAND ROAD, SOLIHULL, WEST MIDLANDS, B92 7BU"]
So it will be buildingNumberOrName + streets name, then town, county and postcode. There could be more than one street, which could potentially complicate things a bit further?
I was thinking about maybe looping the Object to get the information, something like
Object.keys(data).forEach(key => {
});
But then I think I will have to many inner loops. I have seen mapping, but not sure how this could be used here?
Any advice appreciated.
Thanks
data? what should happen then?buildNameandsubBuildingName? will they always be empty? and willbuildNumberalways be the same asbuildingNumberOrName?