# Does anyone knows node-red has union and struct can define and use?

**URL:** <https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160>\
**Category:** General\
**Created:** [8 July 2021 01:59 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160 "2021-07-08T01:59:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlian168](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jlian168/32/43737_2.png) [@jlian168](https://discourse.nodered.org/u/jlian168)\
**Post date:** [8 July 2021 01:59 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/1 "2021-07-08T01:59:15Z")

</div>

Dear All :

Like title.

Thank u.

---

<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:** [8 July 2021 06:34 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/2 "2021-07-08T06:34:48Z")

</div>

Node-RED is written in JavaScript, so has all the capabilities that language has to offer.

---

<div class="post-metadata">

**Author:** ![jlian168](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jlian168/32/43737_2.png) [@jlian168](https://discourse.nodered.org/u/jlian168)\
**Post date:** [8 July 2021 06:50 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/3 "2021-07-08T06:50:03Z")

</div>

Dear dceejay :

Yeah, Does it like below :

```auto
union
{
    int A;
    char B[2];
} AZ;

```

Cause I can not search it at google...

Thank u.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 July 2021 07:08 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/4 "2021-07-08T07:08:26Z")

</div>

JavaScript is not statically typed.  
JavaScript does not have unions.  
JavaScript does not have structs.

You can only create an object.

```auto
const AZ = {
  A: 0,
  B: ""
}
AZ.A = 123;
AZ.B = "one two three";

```

or make a function

```auto
function makeAZ(A, B) {
  return {
    A: A,
    B: B
  }
}
const AZ = makeAZ(123, "one two three");

```

or make a class and then instantiate instances.

---

<div class="post-metadata">

**Author:** ![jlian168](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jlian168/32/43737_2.png) [@jlian168](https://discourse.nodered.org/u/jlian168)\
**Post date:** [8 July 2021 07:38 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/5 "2021-07-08T07:38:47Z")

</div>

Dear Steve-Mcl :

I will try it.

Thank u.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 September 2021 07:39 UTC](https://discourse.nodered.org/t/does-anyone-knows-node-red-has-union-and-struct-can-define-and-use/48160/6 "2021-09-06T07:39:36Z")

</div>

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