How can I make the identifier variable

how can I make the identifier variable
e.g.

how can I make the identifier variable
e.g.
var identifier = (msg.topic);

msg.payload = {
""+identifier+"" :msg.payload
}
return msg;

//Unfortunately, this method does not work

With:

const identifier = msg.topic;

msg.payload = { [identifier]: msg.payload };

return msg;

that was quick, thank you very much

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