0

I am currently experiencing a problem with my axios request.

Here is an example of the result of my query:

{
"results": [
{
"first_result": "123",
"second_result(abc)": "456"
}
]
}

As you can see, the second line contains parentheses. How can I get this data (here "456"), with my useState?

 axios
      .get(API)
      .then((response) => response.data)
      .then((data) => {
       setObject(data.results[0].second_result(abc)))
        
        
      })

Thank you very much and have an nice day ! =)

Vit Ruve
  • 57
  • 2
  • 7

2 Answers2

0

Like this:

data.results[0]['second_result(abc)']

m-s7
  • 337
  • 1
  • 10
0

You will need to access second_result(abc) using bracket notation because property name is not an valid javascript identifier. like a.results[0]['second_result(abc)']

Shikhar Awasthi
  • 1,172
  • 1
  • 3
  • 13