# Working with an Array

**URL:** <https://discourse.nodered.org/t/working-with-an-array/80224>\
**Category:** General\
**Created:** [1 August 2023 14:41 UTC](https://discourse.nodered.org/t/working-with-an-array/80224 "2023-08-01T14:41:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kc7mrq](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kc7mrq/32/42402_2.png) [@kc7mrq](https://discourse.nodered.org/u/kc7mrq)\
**Post date:** [1 August 2023 14:41 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/1 "2023-08-01T14:41:55Z")

</div>

I am creating an array from 4 different MQTT payloads that monitor a percentage. I then do a difference calculation and post the result to a dashboard. It works, but only if the broker sends message 1-4 during the measurement cycle.

However, debug shows there are times when not all messages are broadcasted during a measurement cycle and the array will randomly see duplicate inputs such as [2,3,2,4] instead of [1,2,3,4].

How would I load an array only when messages 1-4 are received? Any duplicates would be updated while waiting for the final message to arrive

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 August 2023 14:44 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/2 "2023-08-01T14:44:44Z")

</div>

Join as a key/value object, then you can be sure of no duplicates, you can easily turn an object to an array if you really require an array.

Without seeing an export of your flow I can not give an example.

---

<div class="post-metadata">

**Author:** ![kc7mrq](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kc7mrq/32/42402_2.png) [@kc7mrq](https://discourse.nodered.org/u/kc7mrq)\
**Post date:** [1 August 2023 15:05 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/3 "2023-08-01T15:05:08Z")

</div>

I'll take a look at the join node tonight and play around with it. I'll post the flow next time.

Thanks for the advise.

Corey

---

<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:** [1 August 2023 15:24 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/4 "2023-08-01T15:24:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kc7mrq](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kc7mrq/32/42402_2.png) [@kc7mrq](https://discourse.nodered.org/u/kc7mrq)\
**Post date:** [2 August 2023 04:31 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/5 "2023-08-02T04:31:13Z")

</div>

Colin and E1SID,  
The join node worked like a charm and my flow now works as expected

Thanks for the help,

Corey.

---

<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:** [1 October 2023 04:32 UTC](https://discourse.nodered.org/t/working-with-an-array/80224/6 "2023-10-01T04:32:04Z")

</div>

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