# Variable path name in object

**URL:** <https://discourse.nodered.org/t/variable-path-name-in-object/68989>\
**Category:** General\
**Created:** [13 October 2022 14:23 UTC](https://discourse.nodered.org/t/variable-path-name-in-object/68989 "2022-10-13T14:23:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiki](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiki](https://discourse.nodered.org/u/kiki)\
**Post date:** [13 October 2022 14:23 UTC](https://discourse.nodered.org/t/variable-path-name-in-object/68989/1 "2022-10-13T14:23:46Z")

</div>

Hi,

I'm using a function node and want to name the "store path" of the object variable.

At the moment my Output looks like  
"element\_i"

My actual code looks like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8fdfb3e74e4ede8638d23c37d5abfe30f85c2771.png)

But I want to have  
element\_1  
...  
element\_8

I hope anybody can help me to solve my problem.  
Thank you!

---

<div class="post-metadata">

**Author:** ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)\
**Post date:** [13 October 2022 14:31 UTC](https://discourse.nodered.org/t/variable-path-name-in-object/68989/2 "2022-10-13T14:31:08Z")

</div>

The sure fire way is to make a variable for the string value you want to use:

```auto
var elemName = "element_" + i;

```

Then use bracket notation to assign the payload to that key:

```auto
msg.payload[elemName] = {...

```

Bracket notation will interpret a variable into the actual key name and give you what you want.

---

<div class="post-metadata">

**Author:** ![kiki](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiki](https://discourse.nodered.org/u/kiki)\
**Post date:** [14 October 2022 05:54 UTC](https://discourse.nodered.org/t/variable-path-name-in-object/68989/3 "2022-10-14T05:54:21Z")

</div>

yessss! That's working ✨

Thank you for your help @madhouse !

---

<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:** [28 October 2022 05:54 UTC](https://discourse.nodered.org/t/variable-path-name-in-object/68989/4 "2022-10-28T05:54:44Z")

</div>

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