# How do i use a variable in global.get ? i.e. global.get(variablename)

**URL:** <https://discourse.nodered.org/t/how-do-i-use-a-variable-in-global-get-i-e-global-get-variablename/70419>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 November 2022 23:04 UTC](https://discourse.nodered.org/t/how-do-i-use-a-variable-in-global-get-i-e-global-get-variablename/70419 "2022-11-10T23:04:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheBartoMan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thebartoman/32/70534_2.png) [@TheBartoMan](https://discourse.nodered.org/u/TheBartoMan)\
**Post date:** [10 November 2022 23:04 UTC](https://discourse.nodered.org/t/how-do-i-use-a-variable-in-global-get-i-e-global-get-variablename/70419/1 "2022-11-10T23:04:03Z")

</div>

I have wrote a funtion that i want to use multiple times.

I need to do a global.get but instead of the usual global.get("xxxxx") where you specify the specific you want to lookup, i want to use a variable for the value to be looked up. (This will be passed to the function)

TheVariable = msg.variable  
GlobalVal = global.get(TheVariable)

Please can anyone help?

Is this possible ?

---

<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:** [10 November 2022 23:07 UTC](https://discourse.nodered.org/t/how-do-i-use-a-variable-in-global-get-i-e-global-get-variablename/70419/2 "2022-11-10T23:07:44Z")

</div>

> [@TheBartoMan](#):
>
> TheVariable = msg.variable  
> GlobalVal = global.get(TheVariable)

```auto
let TheVariable = msg.variable;
let GlobalVal = global.get(TheVariable);

```

I think you answered your own question, did you try it?

---

<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:** [9 January 2023 23:08 UTC](https://discourse.nodered.org/t/how-do-i-use-a-variable-in-global-get-i-e-global-get-variablename/70419/3 "2023-01-09T23:08:34Z")

</div>

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