0

See please the following code which works fine:

var fileContent = app.ReadFile("/sdcard/request-result.json"); // Get JSON content
var count = 0;
var values = JSON.parse(fileContent);
var type = "airTemperature";
console.log(values.hours[count].airTemperature.sg); // this display the right value

I would like to use content of type ("airTemperature") instead of airTemperature to get the same result:

console.log(values.hours[count].keys(type).sg); // Something like this but this doesn't work!
Vega
  • 27,856
  • 27
  • 95
  • 103
Swiftiti
  • 39
  • 5
  • `values.hours[count][type].sg` ? https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – Taplar Oct 05 '20 at 15:43
  • You're not trying to use the string as a variable name, you want to use it as a property name. It should be `hours[count][type].sg` – Barmar Oct 05 '20 at 15:45

0 Answers0