Rostyslav
Rostyslav

Reputation: 81

Get JSON data with Javascript

To access specific JSON data i need to access Main -> Listing -> c44 -> Mydata

c44 is dynamic and can be anything. I have it in my variable - var cc

To access needed data, i write: var result = Main.listing. * how can i specify cc var here? *

Tried console.log (main.listing.["cc"]); but never worked

Upvotes: 2

Views: 126

Answers (2)

Abiral Khanal
Abiral Khanal

Reputation: 106

You can access the data using

Main.Listing[cc]

Upvotes: 0

f-CJ
f-CJ

Reputation: 4481

Since cc is a variable, you should remove the quotes ". Try:

console.log (main.listing[cc]);

Upvotes: 4

Related Questions