skip to Main Content

In this scenario I have a JSON object returned from a query like :

{"details": {"frequency": 2462, "data": "7839792384", "isExpensive": false}, "isConnected": true, "type": "item"}

stored in a variable myVar; and if I do console.log(myVar); I obtain all the object, so if I do console.log(myVar.isConnected); it returns true. But if i do console.log(myVar[0].data); it returns me undefined and it crashes… how can be managed this valid json object about data subitem?

Thanks in advance to all!
Cheers!

2

Answers


  1. You need to select it from "details".
    You are trying to select it like an array myVar[0] will work if you have:['something','otherThing']

    This will select you the ‘something’.

    In you case you need to do mayVar.details.data or and it will do the job 🙂

    enter image description here

    Login or Signup to reply.
  2. You are getting an error because you are trying to access the whole object.
    Just do myVar.details[0] and you will get the specific data.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search