javascript - How to get x, y from nested object -


this question has answer here:

i have error on line console.log(row.data.x) see https://jsfiddle.net/ys6j038q/

  var data = '{"data":{"time":"2016-08-08t15:13:19.605234z","x":20,"y":30}}{"data":{"time":"2016-08-08t15:13:19.609522z","x":30,"y":40}}';               var sanitized = '[' + data.replace(/}{/g, '},{') + ']';              var rows = json.parse(sanitized);   console.log(rows);    for(var row in rows){     console.log(row.data.x);     console.log(row.data.y);   } 

you use foreach @ context not for..in

rows.foreach(function(row){   console.log(row.data.x);   console.log(row.data.y); }); 

for..in give enumerable properties array object such 0 , 1. not give elements in array.

demo


Comments