# Msg.string + variable

**URL:** <https://discourse.nodered.org/t/msg-string-variable/62453>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 May 2022 13:36 UTC](https://discourse.nodered.org/t/msg-string-variable/62453 "2022-05-10T13:36:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sniicker](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniicker/32/56525_2.png) [@sniicker](https://discourse.nodered.org/u/sniicker)\
**Post date:** [10 May 2022 13:36 UTC](https://discourse.nodered.org/t/msg-string-variable/62453/1 "2022-05-10T13:36:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 May 2022 13:51 UTC](https://discourse.nodered.org/t/msg-string-variable/62453/2 "2022-05-10T13:51:50Z")

</div>

Try...

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

```

This is known as [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation)

---

<div class="post-metadata">

**Author:** ![sniicker](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniicker/32/56525_2.png) [@sniicker](https://discourse.nodered.org/u/sniicker)\
**Post date:** [10 May 2022 14:09 UTC](https://discourse.nodered.org/t/msg-string-variable/62453/3 "2022-05-10T14:09:14Z")

</div>

@Steve-Mcl  
Thx thats working fine!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 May 2022 14:09 UTC](https://discourse.nodered.org/t/msg-string-variable/62453/4 "2022-05-24T14:09:52Z")

</div>

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