@zenofmud yes, i tried but the error is coming when msg.payload[0] is undefined and not when have a value. I don't find an all in one solution.
To be clearer I enter the full code:
if (msg.payload[0] != "undefined"){
if (msg.payload[0].r_id > 0 && msg.payload[0].r_id != "undefined"){
let formatobject = [{ "Nessuno": 0 }];
for (let i = 0; i < msg.payload.length; i++) {
let tempnome = msg.payload[i].r_nome;
let tempid = msg.payload[i].r_id;
let tempobject = {};
tempobject[tempnome] = tempid;
formatobject.push(tempobject);
}
msg1.options = formatobject;
node.send([msg1, null, null, null, null, null, null]);
}
}