0

I get this log by console.log(data);:

enter image description here

I'm trying to target data by data[0].data but it's not working. I get Uncaught TypeError: data[0] is undefined.

Huangism
  • 16,278
  • 7
  • 48
  • 74
Grasper
  • 1,293
  • 12
  • 26
  • 2
    Please use `console.log(JSON.stringify(data, null, 2))` and post the data as text, not as a picture of text. – Heretic Monkey Mar 31 '21 at 20:45
  • Generally occurs when you try to access the array before an asynchronous operation has populated it. Check the length , it's probably zero. The console will show updates made to that object after you log it – charlietfl Mar 31 '21 at 20:46
  • With JSON.stringify I get [] an empty array – Grasper Mar 31 '21 at 20:49
  • @HereticMonkey it does answer but it won't tell me how to fix it! – Grasper Mar 31 '21 at 20:51
  • We are going to need more context, then. Because clearly what you are `console.log`-ing is not the same thing as you are actually trying to access. – Sumner Evans Mar 31 '21 at 20:52
  • I have 2 AJAX calls and I'm pushing the data into it. – Grasper Mar 31 '21 at 20:54
  • http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron – Heretic Monkey Mar 31 '21 at 20:55
  • Most notably https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – connexo Mar 31 '21 at 21:00

0 Answers0