# Setting the key of an object to the value of an variable

**URL:** <https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714>\
**Category:** General\
**Created:** [30 September 2021 11:49 UTC](https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714 "2021-09-30T11:49:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [30 September 2021 11:49 UTC](https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714/1 "2021-09-30T11:49:06Z")

</div>

msg.payload = myObject('DGWZ\_temp\_offset');  
node.send(msg);  
return null;

function myObject(key){  
let value = global.get(key);  
return = {key.valueOf():value}; ????????  
}

result should be {'DGWZ\_temp\_offset':value}

your help is very much appreciated.

---

<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:** [30 September 2021 11:53 UTC](https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714/2 "2021-09-30T11:53:12Z")

</div>

> [@juntiedt](#):
>
> return = {key.valueOf():value};

Try...

```auto
return = {[key]: value};

```

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [30 September 2021 12:39 UTC](https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714/3 "2021-09-30T12:39:04Z")

</div>

> [@juntiedt](#):
>
> msg.payload = myObject('DGWZ\_temp\_offset');  
> node.send(msg);  
> return null;
> 
> function myObject(key){  
> let value = global.get(key);  
> return = {key.valueOf():value}; ????????  
> }

Hi Steve,  
many thanks!  
it works ok 🙂  
Hannes

---

<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:** [14 October 2021 12:39 UTC](https://discourse.nodered.org/t/setting-the-key-of-an-object-to-the-value-of-an-variable/51714/4 "2021-10-14T12:39:55Z")

</div>

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