1

I have some JSON data - on doing console.log(json.children[0]) I'm returned:

enter image description here

Now I'm trying to obtain the item value so I can update it.

I'm trying to get the value console.log(json.children[0].value) however it keeps returning undefined.

Any ideas what I'm doing wrong or mis-understanding?

Thanks.

userMod2
  • 8,312
  • 13
  • 63
  • 115

1 Answers1

4

I can't help but notice the fact that the initial log:

Object {name: "Chocolate", children: Array[2]}

... is completely different to the expanded values shown.

It is worth noting the i mark in the console.

Object value at left was snapshotted when logged, value below was evaluated just now.

This suggests that when you actually call console.log(json.children[0]), it only has the two properties name and children. The other properties, including dx, dy and the sought value, aren't added until later in the code.

To get these values, you will have to attempt accessing them after the code that generates them runs. Of course without seeing more details on your code it's impossible to say when/where that should be, but this is what I have for you with what you've provided.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592