0

I'm trying to access a key of an object but i'm not getting what im expecting.

Login the object and the key gives me differents values:

    console.log(this.state.classes[0])
    console.log(this.state.classes[0].image)

enter image description here

If i store it as a global variable in the chrome console, I get this:

{
"id":"LATRwSQq3qmozLgBPosk",
"createdAt":{"seconds":1566068473,"nanoseconds":879000000},
"description":"GrapplingGrapplingGrapplingGrapplingGrappling",
"image":"https://firebasestorage.googleapis.com/v0/b/berserkerdojomanager.appspot.com/o/imgs%2Fgrappling.jpg?alt=media&token=e7fc0c5e-63ba-4e57-81a2-1b548a4c3da0",
"sport":"Grappling",
"tittle":"Grappling"
}

Is it because is an url?

Xhark
  • 781
  • 1
  • 9
  • 24
  • Can you add the output of this console.log(this.state.classes[0]) – Rishab Aug 18 '19 at 05:59
  • 1
    Is `this.state.classes[0].image` modified AFTER `console.log` was done? Because, objects hold references and are reevaluated when you expand them in console. – adiga Aug 18 '19 at 05:59
  • @Xhark I don't understand what is wrong. It seems like the logs are correct. – 10101010 Aug 18 '19 at 06:01
  • @Rishab console.log(this.state.classes[0]) is the first one. It's in class.js:21 – Xhark Aug 18 '19 at 06:04
  • The object is modified after the logging. Check the preview of `this.state.classes[0]`. It still says `image: grappling.jpg`. Try logging `console.log(JSON.parse(JSON.stringify(this.state.classes[0])))` – adiga Aug 18 '19 at 06:05
  • Can you please copy and paste the json here so we can help you out without screenshot – Rishab Aug 18 '19 at 06:05
  • @10101010 how image in the preview and the second log are different to the path i'm seeing in the expanded object of the first one? One is just a file name, and the other is the url(and that's what i need to access but i don't know how) – Xhark Aug 18 '19 at 06:06

0 Answers0