Msg.string + variable

Hy out there,
I'm on the line right now, please help me.

I have a msg looking like this:

msg.payload : {
"String1" : 10,
"String2" : 20,
"String3" : 30,
"String4" : 40
}

Now i whant do get the value of one of these strings dynamicaly within a function node.

var Number = 3;

msg.payload = msg.payload + Number;

I want the msg to like now like this:
msg.payload = 30

But this doesnt work. Can anyone help me please to bring that in a correct form.

THX

Try...

const num = 3;
const prop= "String" + num;
msg.payload = msg.payload[prop];
return msg;

This is known as bracket notation

@Steve-Mcl
Thx thats working fine!!

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