0

My JSON data:

[{"day0":"0","day1":"0","day2":"2","day3":"1","day4":"1"}]

I have tried this and it works for me:

var Respuesta=jQuery.parseJSON(JSON);

data.setValue(0, 1,Respuesta[0].day0);
data.setValue(1, 1,Respuesta[0].day1);
data.setValue(2, 1,Respuesta[0].day2);
data.setValue(3, 1,Respuesta[0].day3);
data.setValue(4, 1,Respuesta[0].day4);

but I need to do it on loop

var column = ["day0", "day1", "day2", "day3", "day4", "day5", "day5", "day6", "day7", "day8", "day9", "day10", "day11", "day12", "day13", "day14", "day15"];

for (i = 0; i < 5; i++) {
  data.setValue(i, 1,Respuesta[0].column[i]);
}

I think I have a problem on this column[i]. Please could you help me with that?

Ivar
  • 6,138
  • 12
  • 49
  • 61
Elhannaoui
  • 23
  • 3
  • 1
    Change `Respuesta[0].column[i]` to `Respuesta[0][column[i]]`. – Ivar Mar 27 '21 at 12:13
  • 1
    Also don't call your string with JSON "`JSON`". It shadows the JSON object. (If you give it another name you can also use `JSON.parse()` instead of `jQuery.parseJSON()` and then you can get rid of jQuery if that's the only thing you use it for.) – Ivar Mar 27 '21 at 12:15

0 Answers0