# Modifying object variable name

**URL:** <https://discourse.nodered.org/t/modifying-object-variable-name/9042>\
**Category:** General\
**Created:** [16 March 2019 00:11 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042 "2019-03-16T00:11:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tzeeth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tzeeth/32/6825_2.png) [@tzeeth](https://discourse.nodered.org/u/tzeeth)\
**Post date:** [16 March 2019 00:11 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/1 "2019-03-16T00:11:20Z")

</div>

Hi!  
I am having some trouble with this simple task:  
I have a msg.payload like this:  
"response": "221321312"  
And I want to be able to change it for "WhateverIWant":"221321312" .  
I have tried with change and switch but I am lost, it would be sweet if you can help me.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 March 2019 00:28 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/2 "2019-03-16T00:28:28Z")

</div>

> [@tzeeth](#):
>
> "response": "221321312"

Do you mean that:

```
msg.payload = {'response':'221321312"}

```

In other words, the payload is an object?

If so:

```
msg.payload = { 'WhateverIWant': msg.payload.response }

```

---

<div class="post-metadata">

**Author:** ![tzeeth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tzeeth/32/6825_2.png) [@tzeeth](https://discourse.nodered.org/u/tzeeth)\
**Post date:** [16 March 2019 09:14 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/3 "2019-03-16T09:14:50Z")

</div>

Thanks! I always forget about objects that was my error.  
Regards!

---

<div class="post-metadata">

**Author:** ![R0bbe](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@R0bbe](https://discourse.nodered.org/u/R0bbe)\
**Post date:** [5 November 2021 09:37 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/4 "2021-11-05T09:37:03Z")

</div>

Is there a possibility to make the object property 'WhateverIWant' a string variable?

So that it can be changed dynamically during the running of the program?  
For example for each loop adding another number to the variable as indicator?

string = 'WhateverIWant' + string(incrementing value)  
msg.payload = { string: msg.payload.response }

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 November 2021 10:10 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/5 "2021-11-05T10:10:43Z")

</div>

> [@R0bbe](#):
>
> msg.payload = { string: msg.payload.response}

`msg.payload = {[string]: msg.payload.response};`  
or  
`msg.payload[string] = msg.payload.response;`

---

<div class="post-metadata">

**Author:** ![R0bbe](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@R0bbe](https://discourse.nodered.org/u/R0bbe)\
**Post date:** [5 November 2021 10:19 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/6 "2021-11-05T10:19:49Z")

</div>

Thank alot, this fixed my problem!  
Probably a noob mistake because I am new to javascript 🙂

---

<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:** [19 November 2021 10:20 UTC](https://discourse.nodered.org/t/modifying-object-variable-name/9042/7 "2021-11-19T10:20:12Z")

</div>

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