{"item":{"icon":"ANOTHER LINK","icon_large":"ANOTHER LINK","id":385,"type":"Default","typeIcon":"ANOTHER LINK","name":"Shark","description":"I should be cautious when consuming this.","current":{"trend":"neutral","price":"1,239"},"today":{"trend":"positive","price":"+15"},"members":"true","day30":{"trend":"positive","change":"+3.0%"},"day90":{"trend":"positive","change":"+52.0%"},"day180":{"trend":"positive","change":"+37.0%"}}}
I am attempting to interpret this json array using Javascript.
if(message.toLowerCase().substring(0,5) == "!item") {
var item = message.substring(6,message.length)
var index = 0;
var found;
var entry;
for (index = 0; index < config.length; ++index) {
entry = config[index];
if (entry.name == item) {
var request = require('request');
var url = "ANOTHER LINK"+ entry.id
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var gestat = JSON.parse(body);
console.log(gestat.item[6].price);
} else {
console.log("Received an error: ", error, ", status code: ", response.statusCode);
}
});
if (index > index.length) {
client.action(channel,"This item does not exist!")
}
}
}
}
});
I am trying to retrieve the price but each time I do
console.log(gestat.item[6].price);
The console shows undefined.