# Group an array operation function

**URL:** <https://discourse.nodered.org/t/group-an-array-operation-function/67128>\
**Category:** General\
**Tags:** function-node\
**Created:** [30 August 2022 14:46 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128 "2022-08-30T14:46:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejoldu94](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Alejoldu94](https://discourse.nodered.org/u/Alejoldu94)\
**Post date:** [30 August 2022 14:46 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/1 "2022-08-30T14:46:51Z")

</div>

Hello, I want to perform an addition operation, I have several inputs, they are DINT type numbers, but I want to group them in an array to add them, but it does not allow me, I get an error. How can I print an array?

var e1= msg.payload  
var e2= msg.payload

const value = [  
{

```
"value": `${e1}`

```

},

];  
const value1 = [  
{

```
"value1": `${e2}`

```

},

];

return [e1,e2];

 ![oee](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea38386fb8e2a79fac2a45c52a291c988ef5330f.png)

---

<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:** [30 August 2022 14:59 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/2 "2022-08-30T14:59:24Z")

</div>

`msg`s never travel down different the wires at the same time. Never.

So, in order to access the values of the two msgs at the same time, you need to join messages into one object.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 August 2022 15:03 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/3 "2022-08-30T15:03:41Z")

</div>

Also, you always need to return a message from a function node. So, apart from the issue identified by Steve, if you want to return an array then you must put it in the message, probably in msg.payload. So you want something like  
`msg.payload = [e1,e2]`  
`return msg`

---

<div class="post-metadata">

**Author:** ![Alejoldu94](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Alejoldu94](https://discourse.nodered.org/u/Alejoldu94)\
**Post date:** [31 August 2022 19:35 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/4 "2022-08-31T19:35:19Z")

</div>

Thank you very much, i try it and that was the solution.

---

<div class="post-metadata">

**Author:** ![Alejoldu94](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Alejoldu94](https://discourse.nodered.org/u/Alejoldu94)\
**Post date:** [31 August 2022 19:44 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/5 "2022-08-31T19:44:54Z")

</div>

Thank you very much, i took your recomendation too.

---

<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:** [14 September 2022 19:45 UTC](https://discourse.nodered.org/t/group-an-array-operation-function/67128/6 "2022-09-14T19:45:54Z")

</div>

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