How can I get the 'address' array within of request response object below?
{
"title": "MRS.",
"name": "Aluno",
"lastName": "3",
"birthday": "2019-08-31",
"address": [
{
"addressName": "rua 2",
"zipCode": "13901264",
"city": "amparo",
"state": "sp",
"country": "brasil"
},
{
"addressName": "rua 2",
"zipCode": "13901264",
"city": "amparo",
"state": "sp",
"country": "brasil"
},
]
}
If I save this object in a state called customer and print console.log(customer.address) it works well and I can see the address informations, but I can't use map or forEach methods like customer.address.forEach, I receive an error :(
addressis an object not an array. Which is why array methods such as forEach won't work on it,Object.values(customer.address)will give you an array of values which you can useforEachon. SimilarlyObject.keysto get an array of the keys, andObject.entriesto get an array of[key, value]pairsconsole.log(customer.address.addressName, customer.address.city)etcaddressbeforecustomerhas been populated with data