# Split array after link OUT / IN

**URL:** <https://discourse.nodered.org/t/split-array-after-link-out-in/47435>\
**Category:** General\
**Created:** [21 June 2021 11:04 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435 "2021-06-21T11:04:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [21 June 2021 11:04 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/1 "2021-06-21T11:04:07Z")

</div>

Good Mornig,

i've write a flow with 3 Modbus connection; each Modbus connection retrive an array data each of 95 elements. Then i've link out these 3 array to other flow.

On flow "data", i've use link IN

Now, how i can read each elements of each array?

For istance:

- array 1 = [1, 2, 3, 4, 5, 6 ....]
- array 2 = 10, 20, 30, 40, 50, 60 ...]
- array 3 = [100, 200, 300, 400, 500, 600 ...

I need a function to retrive the therd element of each array [3, 30, 300]

Thanks to everyone for any advice

By, Jumpier

 ![nr_01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de851b7d36ba693e332933c437f8c0b933c0caa4.png)  
 ![nr_03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b0b9745d9c69214b2f19a98f6f7591f982ae11c0.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:** [21 June 2021 11:30 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/2 "2021-06-21T11:30:57Z")

</div>

> [@jumpier](#):
>
> I need a function to retrive the therd element of each array [3, 30, 300]

Do you need all 3 values at the same time or just the 3rd value of the data passing through?

If you need them all at the same time and need the value of all 3 third elements in a new array as you wrote (`[3,30,300]`) then you will need to join the data from your three nodes so that you can access all three arrays at once. Then it will be a simple case of ...

```auto
msg.payload = [msg.payload.SQ1[2], msg.payload.QF1[2], msg.payload.QF2[2]]
return msg;

```

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

* * *

PS, if you intend on converting all the modbus INT16 values into nicely named strings/bools/floats/int32s etc, you might want to look at [buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser).

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [21 June 2021 11:41 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/3 "2021-06-21T11:41:09Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> msg.payload = [msg.payload.SQ1[2], msg.payload.QF1[2], msg.payload.QF2[2]]
> return msg;
> 
> ```

Thanks,

but if SQ1, QF1 and QF2 don't raise data togheter, function terminate witha a error?  
Is possible "Try / Catch" error inside function code??

---

<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:** [21 June 2021 11:43 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/4 "2021-06-21T11:43:54Z")

</div>

> [@jumpier](#):
>
> but if SQ1, QF1 and QF2 don't raise data togheter, function terminate witha a error?

Thats what the join node is for - read/watch the link I posted.

> [@Steve-Mcl](#):
>
> 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:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [21 June 2021 12:12 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/5 "2021-06-21T12:12:05Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> msg.payload = [msg.payload.SQ1[2], msg.payload.QF1[2], msg.payload.QF2[2]]
> return msg;
> 
> ```

working thanks a lot

---

<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:** [5 July 2021 12:12 UTC](https://discourse.nodered.org/t/split-array-after-link-out-in/47435/6 "2021-07-05T12:12:20Z")

</div>

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