I have a problem, I'm trying to use the Pokemon API, but when I try to access the attack, HP, and speed stats, it shows undefined
for all Pokemon! Can anyone tell me what's wrong with the API call?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
I have an index.js file to test API reception and this is what it returns:
1 2 3 4 5 6 7 8 |
|
API structure:
P粉4035496162024-04-07 10:03:55
Your current code does not properly account for the JSON structure - it is looking for the name
property in the root of each object in the array. You need to use Destructuring to access the stat
properties directly in the condition:
1 2 3 |
|
Or you can change stat.name
to stat.stat.name
.