# How to concatenate arrays

**URL:** <https://discourse.nodered.org/t/how-to-concatenate-arrays/464>\
**Category:** FAQs\
**Created:** [29 May 2018 08:26 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464 "2018-05-29T08:26:45Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 08:26 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/1 "2018-05-29T08:26:45Z")

</div>

Hi,  
How i can to concatenate 2 or 3 output(array 1D) of Modbus TCP client node in one array(1D) ?  
example : **Modbus1 =\> msg.payload =\> [0, 0, 76, 71, 13]** and  
**Modbus2 =\> msg.payload =\> [5, 2, 5, 54, 21]**  
**Modbus3 =\> msg.payload =\> [9, 9, 9, 9, 9]**  
i want to find in ouput msg.modbus [0, 0, 76, 71, 13, 5, 2, 5, 54, 21,9, 9, 9, 9, 9].

And how i can to change the output name of my modbustcpip, instead of having msg.payload i search to have msg.(Mytitle).

Thank you for your help.

---

<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:** [29 May 2018 09:25 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/2 "2018-05-29T09:25:18Z")

</div>

Googling for  
javascript concatenate arrays  
gives  
[https://www.w3schools.com/jsref/jsref\_concat\_array.asp](https://www.w3schools.com/jsref/jsref_concat_array.asp)

Sorry, I don’t understand your second question

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 09:31 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/3 "2018-05-29T09:31:11Z")

</div>

Thank you for your answer, but how can do it in my function if i have two output of my ModbusTcpip1 and ModbusTcpip1 than who have the same name(msg.payload)?  
This is my secend question.

---

<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:** [29 May 2018 09:57 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/4 "2018-05-29T09:57:48Z")

</div>

Do you mean the arrays are coming in on separate messages? If so then you can use the Join node in Manual mode to combine the two message payloads into a single message containing a key/value object and then you can combine the arrays.

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 10:07 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/5 "2018-05-29T10:07:22Z")

</div>

![Sans%20titre](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/2bf7724e743ce75e5b64a424b3da75dbaccf81b5.png)  
that's what I want do  
I'm sorry, I can't explain well because I'm a beginner on node-red  
thank you Colin for your help (y) (y)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 May 2018 10:49 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/6 "2018-05-29T10:49:04Z")

</div>

Most nodes will expect the “valuable” data to be in msg.payload so changing it to msg.somethingelse may cause you problems.

But you can use a **change** node to move data from one place to another.

If your work is Urgent, as per the title, its probably not the best time to use a tool you are a beginner with.

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 11:05 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/7 "2018-05-29T11:05:32Z")

</div>

Thank you ukmoose for your answer  
 ![Sans%20titre](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/0dc4766411fa9f27e4a6413395d2f7f1fa21b855.png)  
but the only way to concatenate the two arrays, it to change the name of the output of each mosbus to integrate them into function **(how can I distinguish between the two output in function, they have the same name "msg.payload"?)**  
I hope you have understood my problem.  
thank you

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 May 2018 11:23 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/8 "2018-05-29T11:23:30Z")

</div>

You could try the suggestion @Colin suggested above [Urgent : Modbus tcp/ip array!](https://discourse.nodered.org/t/urgent-modbus-tcp-ip-array/464/4?u=ukmoose)

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [29 May 2018 12:09 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/9 "2018-05-29T12:09:11Z")

</div>

You can add a change node between the `Mod bus to` node and the `array` function node  
and set e.g. msg.topic=1, the same for the `ReadModBUSLabview` \> msg.topic=2

In your array function first check the msg.topic:

```auto
If (msg.topic === 1) {
  // ...
} else if (msg.topic === 2) {
  // ...
}

```

---

<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:** [29 May 2018 12:40 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/10 "2018-05-29T12:40:16Z")

</div>

> [@imadouino](#):
>
> how can I distinguish between the two output in function, they have the same name “msg.payload”?

Are all these messages coming from one node or from different nodes?  
Also do they have different topics?

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 12:54 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/11 "2018-05-29T12:54:52Z")

</div>

This is exactly what I was looking for, I did not make the difference between the topic and the playload for each node , I think with this method I can do what I want

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 12:56 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/12 "2018-05-29T12:56:12Z")

</div>

> [@imadouino](#):
>
> This is exactly what I was looking for, I did not make the difference between the topic and the playload for each node , I think with this method I can do what I want

messages coming from different nodes in array forms and they have different topics.

Thank youu

---

<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:** [29 May 2018 13:25 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/13 "2018-05-29T13:25:46Z")

</div>

> [@imadouino](#):
>
> messages coming from different nodes in array forms and they have different topics

In that case you can do what I originally suggested, using a Join node to give you a key/value object with all the payloads with individual keys.

---

<div class="post-metadata">

**Author:** ![imadouino](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imadouino/32/487_2.png) [@imadouino](https://discourse.nodered.org/u/imadouino)\
**Post date:** [29 May 2018 14:23 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/14 "2018-05-29T14:23:28Z")

</div>

Perfect my problem is solved, Thank you Colin,

---

<div class="post-metadata">

**Author:** ![Salvatore](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Salvatore](https://discourse.nodered.org/u/Salvatore)\
**Post date:** [15 October 2020 16:08 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/15 "2020-10-15T16:08:38Z")

</div>

hi,  
i have the same problem but i can't solve it.  
Can you help me?

---

<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:** [15 October 2020 16:24 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/16 "2020-10-15T16:24:41Z")

</div>

This thread is two years old, please start a new one describing your problem. If you are trying to solve it using the marked solution above then explain what the problem is when you try that.

---

<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:** [15 October 2020 16:24 UTC](https://discourse.nodered.org/t/how-to-concatenate-arrays/464/17 "2020-10-15T16:24:51Z")

</div>


