Fill dropdown by function node

Hello experts!

I'm trying to fill a dropdown but cant get it work! Whats wrong with my code?

var msg2 = {};

msg2.options = [];

for (let i=0; i<msg.payload.length; i++)
{
    var label = msg.payload[i].Timestamp__OrderStart.toLocaleString()+"; Anzahl: "+msg.payload[i].PartsCount.toString();
    var value = i;
    var s = {label:value};
    
    msg2.options.push(s);
}

return msg2;
{"options":[{"label":0},{"label":1},{"label":2},{"label":3},{"label":4},{"label":5},{"label":6},{"label":7},{"label":8},{"label":9}],"_msgid":"82856354.20b3"}

try var s = {[label]: value};
Javascript interprets label as a string key not a var, the square bracket tells it to treat it a a variable.

1 Like

Thats it! Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.