0
Object.keys(data).forEach((key) => {
        bannerData[key] = data[key][0];
        console.log(key);
        if (key == "timestamp") {
          labels.push(data[key]);
          console.log("wtf");
          console.log(labels);
        } else {
          datasets.push(data[key]);
        }
      });

generates

exhaust_humidity 
exhaust_temperature 
intake_humidity 
intake_temperature
lights 
relay
room_humidity 
room_temperature 
soil_moisture_1 
soil_moisture_2 
soil_moisture_3 
soil_moisture_4 
soil_moisture_5 
soil_moisture_6
soil_moisture_7 
soil_moisture_8 
timestamp

the console.log("wtf"); is never called, because the last key never registers as equal to "timestamp".

Not sure what I'm missing.

The Candy King
  • 89
  • 1
  • 1
  • 10

1 Answers1

1

const data = {
  not_timestamp: 1,
  timestamp: 2,
}

const bannerData = {}
const datasets = []
const labels = []

Object.keys(data).forEach((key) => {
  bannerData[key] = data[key][0];
  console.log(key);
  if (key == "timestamp") {
    labels.push(data[key]);
    console.log("wtf");
    console.log(labels);
  } else {
    datasets.push(data[key]);
  }
});

Works fine. If I had to guess, labels is undefined in your script, causing it to error before "wtf" is printed.

mpen
  • 272,448
  • 266
  • 850
  • 1,236