# How to create a javascript object using change node and flow variable

**URL:** https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023
**Category:** General
**Created:** [12 March 2020 10:24 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023 "2020-03-12T10:24:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 March 2020 10:24 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/1 "2020-03-12T10:24:01Z")

</div>

I know I can do this in a `function` node, but want to do it in a `change` node but I can't figure out how. I want to dynamically change the icon for a button based on a flow contect variable.

I use an `inject` to store an icon type like 'mi-clear' into flow.symbol.  
In a `change` node I set msg.symbol to flow.symbol  
Now I want to end up with msg.ui\_control being `{"icon":"mi-clear"}` and I can't figure out how to do it.

Any hints or suggestions?

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [12 March 2020 10:54 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/2 "2020-03-12T10:54:04Z")

</div>

Make flow.symbol an array of values like:

`{"icon":"mi-clear"}`  
`{"icon":"mi-another"}`  
`{"icon":"mi-yet another"}`

And do a lookup based on the input?

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [12 March 2020 11:09 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/3 "2020-03-12T11:09:32Z")

</div>

How about a template node with below config ?

![a-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/37a7543b60a6824d119c6e26b39a0bf222526c25.png)

---

<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: [12 March 2020 11:13 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/4 "2020-03-12T11:13:18Z")

</div>

Use the JSONata expression: `{ "icon": $.symbol }`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/471a512103ee822c1b5d0be18c205f7778ab241b.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 March 2020 11:22 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/5 "2020-03-12T11:22:02Z")

</div>

Thanks Nick, one of these days I'll understand jsonata ("Yeah right!" my brain says)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [26 March 2020 11:22 UTC](https://discourse.nodered.org/t/how-to-create-a-javascript-object-using-change-node-and-flow-variable/23023/6 "2020-03-26T11:22:04Z")

</div>

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