# Node-red custom node variable undefined

**URL:** https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205
**Category:** Developing Nodes
**Created:** [6 September 2019 16:37 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205 "2019-09-06T16:37:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![krishnaa208](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnaa208/32/11847_2.png) [@krishnaa208](https://discourse.nodered.org/u/krishnaa208)
#### Post date: [6 September 2019 16:37 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/1 "2019-09-06T16:37:28Z")

</div>

Hey I am trying to build a node for that taking input from user in dashboard and filter data based on input but \*\* i count not access array variable in .js ( undefined )\*\* file can someone help

**contents of .html are :**

```auto
<script type="text/javascript">
    RED.nodes.registerType('hello-world',{
        category: 'function',
        color: '#e2d96e',
        defaults: {
            name: {value:""},
            dataVariable : { value : [1,2,3] } 
        },
        inputs:1,
        outputs:1,
        icon: "white-globe.png",
        label: function() {
            return this.name||"hello-world";
        }
    });
</script>

<script type="text/x-red" data-template-name="hello-world">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
</script>

<script type="text/x-red" data-help-name="hello-world">
    <p>A simple node that changes the message payloads to Hello World</p>
</script>

```

**contents of .js :**

```auto
module.exports = function (RED) {
    "use strict";
    function HelloWorldNode(config) {
        RED.nodes.createNode(this, config);
        this.dataVariable = config.dataVariable ;
        var node = this;
        this.on('input', function (msg) {
            msg.payload = node.dataVariable;
            node.send(msg);
        });
    }
    RED.nodes.registerType("hello-world", HelloWorldNode);
};

```

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [6 September 2019 16:40 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/2 "2019-09-06T16:40:55Z")

</div>

_(moving your question to the category that handles custom nodes and support requests while creating them, so you might get better help on it)_

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [6 September 2019 16:54 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/3 "2019-09-06T16:54:12Z")

</div>

Did you open your node's config panel after adding it? If not, I'm not sure that your default values have been set yet?

I normally also set the defaults in the js file as well so as to be sure.

---

<div class="post-metadata">

### Author: ![krishnaa208](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnaa208/32/11847_2.png) [@krishnaa208](https://discourse.nodered.org/u/krishnaa208)
#### Post date: [6 September 2019 18:18 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/5 "2019-09-06T18:18:51Z")

</div>

Yaa i did it and i am not trying set defualts its just example code. i want to pass data (array) from .html form to .js . i had tried different things but nothing worked.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [6 September 2019 21:00 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/6 "2019-09-06T21:00:31Z")

</div>

> [@krishnaa208](#):
>
> i am not trying set defualts

Actually, you are. Without a default value, it will be undefined. Try also setting a default in the .js file such as:

```javascript
this.dataVariable = config.dataVariable || [9,8,7] ;

```

---

<div class="post-metadata">

### Author: ![krishnaa208](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnaa208/32/11847_2.png) [@krishnaa208](https://discourse.nodered.org/u/krishnaa208)
#### Post date: [7 September 2019 08:15 UTC](https://discourse.nodered.org/t/node-red-custom-node-variable-undefined/15205/7 "2019-09-07T08:15:18Z")

</div>

I found the solution i need to remove node from flow pallete and add it again. After restarting server changes in html were rendered without adding and removeing node so assume change are reflected but they hadn't . I am new to commuinty Thanks for Help.
