html - When referring to a JSONObject in javascript, how do I refer to it using a variable (rather than the name itself)? -



html - When referring to a JSONObject in javascript, how do I refer to it using a variable (rather than the name itself)? -

i looked other stackoverflow posts this, none seemed work. i'll post code below:

$.getjson('bugs.json', function (data) { ( var observer = 1; observer <= data.numobservers; observer++) { var observername = "num" + observer; var specs = ['congestion', 'bloodflow']; ( var spec in specs) { var tablecode = "<br><table id=\"" + observer + specs[spec] + "\" > <thead> <tr> <th>" + specs[spec] + "</th> <th id=\"value\">value</th> <th id=\"time\">time</th></tr>"; $('body').append(tablecode); var observerobj = data[observername] + " kaka " + data.num1.congestion.values[1]; var selectedspec = specs[spec]; (var = 0; < observerobj[selectedspec].values.length; i++) { tr = $('<tr/>'); tr.append ("<td> name </td>"); tr.append("<td>" + data[observername][spec].values[i] + "</td>"); tr.append("<td>" + data[observername][spec].times[i] + "</td>"); $('#'+observer+spec).append(tr); } } } });

when using browser console log, error observerobj[selectedspec] doesn't work.

thanks in advance help.

edit: exact console error is:

typeerror: observerobj[selectedspec] undefined

var observerobj = data[observername] + " kaka " + data.num1.congestion.values[1];

if reading correctly, observerobj string - not array or object. observerobj[selectedspec] not exist.

javascript html json variables

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -