I see.
Index is not an index.
Ok let’s use a flag instead.
var array = {};
var time = "";
var flag = true;
time = new Date(msg.payload.approvedTime);
var offset = time.getTimezoneOffset();
time = new Date(time.getTime() - (offset*60*1000));
msg.state = time.toISOString().replace("T", " ").substring(0,16)
for (var index in msg.payload.timeSeries.slice(0,67)) {
time = new Date(msg.payload.timeSeries[index].validTime);
offset = time.getTimezoneOffset();
time = new Date(time.getTime() - (offset * 60 * 1000));
array[time.toISOString().replace("T", " ").substring(0, 16)] = { "temp": 0, "wind": 0, "gust": 0, "nederbord": 0, "symbol": 0, "tcc": 0, "tcc_mean": 0, "lcc": 0, "lcc_mean": 0, "mcc": 0, "mcc_mean": 0 };
for (var val in msg.payload.timeSeries[index].parameters) {
if (msg.payload.timeSeries[index].parameters[val]["name"] == "t") {
array[time.toISOString().replace("T", " ").substring(0, 16)].temp = msg.payload.timeSeries[index].parameters[val].values[0]; // { "temp": Math.round(msg.payload.timeSeries[index].parameters[val].values[0]) }
}else if (msg.payload.timeSeries[index].parameters[val]["name"] == "ws"){
array[time.toISOString().replace("T", " ").substring(0,16)].wind = msg.payload.timeSeries[index].parameters[val].values[0];
}else if (msg.payload.timeSeries[index].parameters[val]["name"] == "gust"){
array[time.toISOString().replace("T", " ").substring(0,16)].gust = msg.payload.timeSeries[index].parameters[val].values[0];
}else if (msg.payload.timeSeries[index].parameters[val]["name"] == "pmax") {
array[time.toISOString().replace("T", " ").substring(0, 16)].nederbord = msg.payload.timeSeries[index].parameters[val].values[0];
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "Wsymb2") {
array[time.toISOString().replace("T", " ").substring(0, 16)].symbol = msg.payload.timeSeries[index].parameters[val].values[0];
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "tcc") {
array[time.toISOString().replace("T", " ").substring(0, 16)].tcc = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.tcc = msg.payload.timeSeries[index].parameters[val].values[0];
}
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "tcc_mean") {
array[time.toISOString().replace("T", " ").substring(0, 16)].tcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.tcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
}
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "lcc") {
array[time.toISOString().replace("T", " ").substring(0, 16)].lcc = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.lcc = msg.payload.timeSeries[index].parameters[val].values[0];
}
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "lcc_mean") {
array[time.toISOString().replace("T", " ").substring(0, 16)].lcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.lcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
}
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "mcc") {
array[time.toISOString().replace("T", " ").substring(0, 16)].mcc = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.mcc = msg.payload.timeSeries[index].parameters[val].values[0];
}
} else if (msg.payload.timeSeries[index].parameters[val]["name"] == "mcc_mean") {
array[time.toISOString().replace("T", " ").substring(0, 16)].mcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
if (flag) {
msg.mcc_mean = msg.payload.timeSeries[index].parameters[val].values[0];
}
}
flag = false;
}
}
/* I just left these here for no good reason.
msg.tcc = msg.payload.timeSeries[0].parameters[5].values[0];
msg.tcc_mean = msg.payload.timeSeries[0].parameters[6].values[0];
msg.lcc = msg.payload.timeSeries[0].parameters[7].values[0];
msg.lcc_mean = msg.payload.timeSeries[0].parameters[8].values[0];
msg.mcc = msg.payload.timeSeries[0].parameters[9].values[0];
msg.mcc_mean = msg.payload.timeSeries[0].parameters[10].values[0];
*/
msg.arr = array;
return msg;
Because index wasn’t an index the code failed hard.
But now we set a flag to true and on the first time series it sets the msg.tcc mcc and so on then makes the flag false so that it does not overwrite the values again.