# Get all defined variables

**URL:** <https://discourse.nodered.org/t/get-all-defined-variables/8371>\
**Category:** General\
**Created:** [25 February 2019 13:39 UTC](https://discourse.nodered.org/t/get-all-defined-variables/8371 "2019-02-25T13:39:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [25 February 2019 13:39 UTC](https://discourse.nodered.org/t/get-all-defined-variables/8371/1 "2019-02-25T13:39:13Z")

</div>

Hopefully not too stupid of a question: Do we have the ability to retrieve all flow variables for a given flow, perhaps in the form of an array? If so, how would one go about this?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [25 February 2019 13:50 UTC](https://discourse.nodered.org/t/get-all-defined-variables/8371/2 "2019-02-25T13:50:22Z")

</div>

I assume you mean flow context?

`flow.keys()` returns a list of the names of the variables. You can then use `flow.get()` for each element in that array to get its value.

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [25 February 2019 15:18 UTC](https://discourse.nodered.org/t/get-all-defined-variables/8371/3 "2019-02-25T15:18:54Z")

</div>

That's exactly what I meant, thanks! Sometimes RTFM is tougher when you're bumbling about not knowing the right terms to search... once you replied, I was able to find this in the "writing functions" guide almost right away.

I also quickly threw together an example for anyone to play with if they run across this thread in their own searching. I have no doubt it could be done more elegantly; but what can't, really?

`[{"id":"fe9afd72.aaacd","type":"inject","z":"6da4d638.9f76c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":1080,"wires":[["fe191abf.dd706"]]},{"id":"fe191abf.dd706","type":"function","z":"6da4d638.9f76c","name":"","func":"msg.payload = flow.keys();\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":1080,"wires":[["7d3aa3bd.491114"]]},{"id":"4615c07d.81d37","type":"debug","z":"6da4d638.9f76c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":1080,"wires":[]},{"id":"7d3aa3bd.491114","type":"split","z":"6da4d638.9f76c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":470,"y":1080,"wires":[["d9b8dd89.1c1fa8"]]},{"id":"d9b8dd89.1c1fa8","type":"function","z":"6da4d638.9f76c","name":"","func":"var key = msg.payload;\nvar val = flow.get(key);\nmsg.payload = {\"variable name\":key, \"value\":val};\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":1080,"wires":[["4615c07d.81d37"]]}]`
