javascript - Accessing elements in a Hash Table -
i'm going in circles , confused how access elements in hash table. have returned data json successfully. object object contains 2 columns fips , corresponding value. want access first row. i've tried using raw.fips / raw[fips] , raw[0] returned undefined there data in raw don't know access it.
here ajax if helps
$.ajax({ type: "get", url: webroot + "ws/gis.asmx/censusdata", data: d, contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { fipsdata = data.d; console.log("json object returned data : " + fipsdata); init(regtype, varid); } //ends success function }); //ends ajax call
the ajax returns data , in log there 3141 rows / elements i'm not sure.
var raw = fipsdata; var valmin = infinity; var valmax = -infinity; (var index in raw) { fipscode = raw[fips]; console.log(fipscode); } //log data console.log("fipsdata : " + fipsdata); console.log("raw number :" + raw);//undefined
you're using wrong index in code:
for (var index in raw) { fipscode = raw[fips]; console.log(fipscode); }
you've set index
variable using loop, using fips
when try access it. try changing fipscode = raw[fips];
fipscode = raw[index];
.
also, should hasownproperty
check when looping through object, avoid attempting process methods , such. try this:
for (var index in raw) { if (raw.hasownproperty(index)) { fipscode = raw[index]; console.log(fipscode); } }
if doesn't work then, if can show sample of of returned data, make easier keep troubleshooting.
Comments
Post a Comment