PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 14, 2022

[FIXED] Why am I unable to access this response.data array in ReactJS/Axios?

 October 14, 2022     axios, reactjs     No comments   

Issue

I am trying to access the "players" array coming from this API i've called in axios, the return looks like this when I am printing response.data:

enter image description here

Now, I thought it would be easy to access it, so I tried(without success):

response.data.players (print out all players)
response.data.players[0] (print out first player)
response.data[0] (maybe get the array?)

What am I doing wrong?


Solution

I have a feeling that response.data (based on the screenshot you've attached for response.data) has one more property called response inside it, which has players array. Maybe try using response.data.response.players[0].

Let me know if that doesn't work so I can make necessary changes to the answer :)



Answered By - Harsh Tuwar
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing