# How can I create a default property like array?

**URL:** https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718
**Category:** General
**Created:** [3 April 2019 07:45 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718 "2019-04-03T07:45:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![trujillo](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@trujillo](https://discourse.nodered.org/u/trujillo)
#### Post date: [3 April 2019 07:45 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/1 "2019-04-03T07:45:55Z")

</div>

Hi,

I try to set an array var to store some objects in a node, something like that:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4fa20db6d047a7b65bd84183e9a8181986038e7e.png)

In the image, Atributos is an array with 3 objects, but I can't use this variable in the js file.

Thanks!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [3 April 2019 07:55 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/2 "2019-04-03T07:55:31Z")

</div>

That is not one of the core nodes I recognise. Which node is that ?  
As it's not a core node you may need to contact the author of the node directly and ask them to add to their docs.

---

<div class="post-metadata">

### Author: ![trujillo](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@trujillo](https://discourse.nodered.org/u/trujillo)
#### Post date: [3 April 2019 08:00 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/3 "2019-04-03T08:00:29Z")

</div>

It's a custom node that I'm developing. It's a node that create an entity in Orion Context Broker, and I need an array with the attributes of the entity.

Thanks!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [3 April 2019 08:04 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/4 "2019-04-03T08:04:03Z")

</div>

Ah.. - you will need to build the array into a default property during the oneditsave function and pass it back that way (and vice versa you will need to take the saved version from that property and re-populate the ui during oneditprepare

---

<div class="post-metadata">

### Author: ![trujillo](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@trujillo](https://discourse.nodered.org/u/trujillo)
#### Post date: [3 April 2019 08:08 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/5 "2019-04-03T08:08:50Z")

</div>

Are oneditsave and oneditprepare functions for js file? I try it, but I have the info in the form and it isn't accessible for js file.

Thanks!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [3 April 2019 09:31 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/6 "2019-04-03T09:31:13Z")

</div>

they are javascript functions in the html file - see the docs - [https://nodered.org/docs/creating-nodes/node-html](https://nodered.org/docs/creating-nodes/node-html). Once you have manipulated them into a property defined in the defaults list (eg a hidden field node-input-myArray as myArray in the defaults list), then they will be available in the config on the js side.

---

<div class="post-metadata">

### Author: ![trujillo](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@trujillo](https://discourse.nodered.org/u/trujillo)
#### Post date: [3 April 2019 09:43 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/7 "2019-04-03T09:43:57Z")

</div>

Ok, I can define in the defaults like that?:

defaults: {  
myArray: { value: new Array()}  
}

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [3 April 2019 09:46 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/8 "2019-04-03T09:46:25Z")

</div>

I would go for `myArray: { value: [] }`

---

<div class="post-metadata">

### Author: ![trujillo](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@trujillo](https://discourse.nodered.org/u/trujillo)
#### Post date: [5 April 2019 11:04 UTC](https://discourse.nodered.org/t/how-can-i-create-a-default-property-like-array/9718/9 "2019-04-05T11:04:52Z")

</div>

I try something like that

```auto
RED.nodes.registerType('fiware-in', {
        category: 'Fiware',
        color: '#a6bbcf',
        defaults:{
            name: {value:""},
            fiware_action: {value:"", require:true},
            fiware_host: {value:"", requite:true},
            fiware_entity: {value:"", require:true},
            fiware_attrs_array: {value:[]},
            fiware_options_json: {value:"", require:true}
        },
        inputs:0,
        outputs:1,

```

And then, in the html:

```auto
<div class="form-attr">
            <label for="node-input-fiware_attrs_array"><i class="icon-tag"></i> Atributos </label>
            <input type="text" id="attr_name_1" placeholder="Name">
            <input type="text" id="attr_type_1" placeholder="Type">
            <input type="text" id="attr_value_1" placeholder="Value">
            <div id="addAttr" class="form-row"></div>
            <br>
            <input type="button" name="button_add" value="Añadir atributo" onclick="addAttr()">
            <input type="button" name="button_remove" value="Borrar último atributo" onclick="removeAttr()">
            <br>
            <input type="button" name="button_validate" value="Validar atributos" onclick="validate()">
        </div>

```

The validate button, copy an array with each attribute in fiware\_attrs\_array. But when I try to receive those data in the js file, I have an empty array
