javascript - json keys as numbers -


i have json passed script. not know json keys dynamic.

actually, numbers. that's i'm getting.

 var countries = {"223":"142,143","222":"23,26,25,24","170":"1,2"}; 

i tried access data this:

 var objkey = 223;  (var objkey = "223";) countries.objkey; 

i tried changing json to

 var countries = {"country223":"142,143","country222":"23,26,25,24","country170":"1,2"}; 

... , access this:

 var objkey = "country"+223; (var objkey = "country"+"223";) countries.objkey; 

... again nothing.

any advice appreciated.

instead of this:

countries.objkey; 

do this:

 countries[objkey]; 

with square bracket notation, can use value referenced in variable (or use string or number) reference property name.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -