Hello everyone,
I'm currently trying to parse some data I receive from a request to send only what I want to the html file. I manage to get the data like I want, but when I try to create my object, I can't parse it properly. Here's what I currently have as JS script:
var itemList = [];
items.thermostatList.forEach(function (value,index){
if (value.name.trim() != ""){
itemList += {
"value": "Thermostat: " + value.name
};
}
value.remoteSensors.forEach( function (val, ind){
});
});
console.log("itemList: " + itemList);
var keyInfo = Object.keys(itemList);
console.log("itemList info: " + keyInfo);
Here's the console output:
itemList: [object Object]
itemList info: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
Now, problem is the keys are number. How do I access that?
I tried itemList.forEach(....) and that failed saying forEach is not a function of itemList.
I tried itemList[0] and itemList.0, both failed to compiled. The goal here is to finish with:
var keys = {
result:"ok",
items : itemList
};
res.json(keys);
return;
So afterward, on my html file, I can parse the json and get all items.
Thank you