# Javascript Variable Question

**URL:** <https://community.weweb.io/t/javascript-variable-question/1724>\
**Category:** Developer corner\
**Created:** [January 18, 2023, 6:13am UTC](https://community.weweb.io/t/javascript-variable-question/1724 "2023-01-18T06:13:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [January 18, 2023, 6:13am UTC](https://community.weweb.io/t/javascript-variable-question/1724/1 "2023-01-18T06:13:46Z")

</div>

I have this piece of Javascript I’m using from OrgChartJS

```auto
 var chart = new OrgChart(document.getElementById("tree"), {
            nodeBinding: {
                field_0: "name"
            },
            nodes: [
                { id: 1, name: "Amber McKenzie" },
                { id: 2, pid: 1, name: "Ava Field" },
                { id: 3, pid: 1, name: "Peter Stevens" }  
            ]
        });

```

The code as you see it here works great in my app.

To use it with my own data, I have a workflow that generates an array in the format they require, the output looks something like this.

id: 378, pid : 341, name: “Alessia White”, title: “Human Resources Business Partner”, img: “[https://xcyd-oosa-mas.n7.xano.io/vault/yHMOBGnw/BFFpNnSj62W4SrRiaj59psk90xM/Fq6EUQ../Alessia+White.jpeg?tpl=med:box](https://xcyd-oosa-mas.n7.xano.io/vault/yHMOBGnw/BFFpNnSj62W4SrRiaj59psk90xM/Fq6EUQ../Alessia+White.jpeg?tpl=med:box)”}

If I paste my output direclty into the function, it works. However my output is stored in a Variable or Returned from the Loop generating the data itself, so I need to pass that into the Javascript. I am trying to pass the data stored, but the function will not work. Here is a snippet of code, any idea what I’m doing wrong here?

```auto
var chart = new

OrgChart(document.getElementById("tree"), {
    mouseScrool: OrgChart.action.none,
    nodeBinding: {
        field_0: "name",
        field_1: "title",
        img_0: "img"
    },
    enableDragDrop: false,
    nodes: [ 
                
    variables['32f4ce59-6bca-4b80-b258-311be2ef78fe']
                
                    ]
});

```

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [January 18, 2023, 10:54am UTC](https://community.weweb.io/t/javascript-variable-question/1724/2 "2023-01-18T10:54:56Z")

</div>

Where are you using this code (javascript action, script tag in html, script tag in page head)?  
What is the error you get in the console?

You should try to use the code in a javascript action.

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [January 18, 2023, 3:16pm UTC](https://community.weweb.io/t/javascript-variable-question/1724/3 "2023-01-18T15:16:56Z")

</div>

No errors in the Javascript console. I’m using it inside of an HTML element.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/a/ad03333b37faa6c24a3983f5f83255e742de3bd3.png)

If I use it inside of a regular Javascript action, how would I get the code to print to the page?

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [January 18, 2023, 10:49pm UTC](https://community.weweb.io/t/javascript-variable-question/1724/4 "2023-01-18T22:49:27Z")

</div>

@dorilama I did some more testing here, I think I may see what’s going on.

In Chrome when I print out the array I’m trying to pass I see that the variable test which I am assigning to one part of the array, has leading and ending quotations ("), so I don’t believe it’s being read-in correctly.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/7/71d60c10fb9ad1c94856130ac1a739bef864b821.png)

You’ll also see in my array, it looks like it’s storing it as a string which I suppose is not the expected format. Any idea how to correct this?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/6/6623d6a9701ab482e1bb3f4c5de4a4a2530a2301.png)

Here is code I am using to generate the string to be stored in the array.

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/0/0f5453661b514d5dd5e480e05e1af3d4b18873c7.png)

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [January 19, 2023, 10:00am UTC](https://community.weweb.io/t/javascript-variable-question/1724/5 "2023-01-19T10:00:00Z")

</div>

I think what you want to store is an Object, not a string. Can you try by removing the quote on your formula?

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [January 19, 2023, 3:38pm UTC](https://community.weweb.io/t/javascript-variable-question/1724/6 "2023-01-19T15:38:16Z")

</div>

That did not work, but what did was passing Object. Here is the output I used to get this to work.

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/1/11c49204c15b41988fa7a2f916068469f17c58e6.png)

Trying to push this data to Xano is a whole different challenge though, trying to find some documentation as Arrays are not simple to get into there.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [January 20, 2023, 1:58pm UTC](https://community.weweb.io/t/javascript-variable-question/1724/7 "2023-01-20T13:58:50Z")

</div>

Your screenshots show that you are very confused about what you are doing.  
You are using an html element and executing javascript in the binding function.  
It’s probably better if you just use javascript actions in a workflow.

---

<div class="post-metadata">

**Author:** ![patopt](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@patopt](https://community.weweb.io/u/patopt)\
**Post date:** [January 21, 2023, 8:50pm UTC](https://community.weweb.io/t/javascript-variable-question/1724/8 "2023-01-21T20:50:31Z")

</div>

It actually is working great now 🙂
