Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

processing JSON advanced

I have the following JSON I was wondering how would you process it using JavaScript

I want to console.log teamname. SportsTypes

[
  {
    "teamname": "Bulldogs",
    "nickname": "",
    "SportTypes": {
      "-JZLOh7KtM78I5wAL6Ua": true
    },
    "locations": {
      "-JZLCFtpcuvsYxb5N1Cc": true
    }
  }
]

Open in new window

Avatar of Rob
Rob
Flag of Australia image

Assuming the code you've posted is in myobject:

Console.log(myobject[0].teamname);
Console.log(myobject[0].SportTypes);
Avatar of stargateatlantis
stargateatlantis

ASKER

So would I do this

Console.log(myobject[0].SportTypes['-JZLOh7KtM78I5wAL6Ua']);

Open in new window

Yes, that is what you'd need to do to get that value.

You could also use the for/in loop to get the value too
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial