I'm struggling to extract the necessary information from the array below, which was received from the backend. I need to utilize these values as error messages but my attempts to map have been unsuccessful.
const errorArray = [
{
"candidate": {
"phone_number": [
"Enter a valid phone number."
]
},
"amount": [
"Minimum amount £10"
]
}
]
I want something like the example below, but I can't figure it out?
const phone_number = "Enter a valid phone number."
const amount = "Minimum amount £10"
Edit:
The issue is that I'm unable to access the data using dot notation. I am working with React and errorArray is passed as a prop. While I can console.log(errorArray) and see the array with objects inside, attempting to use dot notation results in an error: Uncaught TypeError: Cannot read properties of null (reading 'candidate').
Do I need to iterate over the array or take a different approach? Any guidance would be greatly appreciated.