# Split an Array of 150 values into shorter 15 Arrays of 10 values

**URL:** <https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247>\
**Category:** General\
**Created:** [15 February 2023 18:41 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247 "2023-02-15T18:41:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakha001](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zakha001](https://discourse.nodered.org/u/zakha001)\
**Post date:** [15 February 2023 18:41 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/1 "2023-02-15T18:41:17Z")

</div>

![Nodered_Array](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3ce0baa287937d69940207e4119abfc187618e7.jpeg)

Hi Everyone!

I am new to node-red. I am receiving an array of 150 values from PLC via OPC UA in node-red. Now I have to upload these to the Thingspeak MATLAB cloud. The cloud has limitations; the channels in the cloud update after every 15 seconds and maximum values that can be uploaded on a channel are 12.

I need to split the Array of 150 values into shorter arrays of 10 values each and also send each shorter array after 15 seconds delay. This is because if I send the values before the 15 second delay, the values get over-ridden.

In short: Split a large Array of 150 values into 15 shorter Arrays of 10 values each after the delay of 15 seconds.

Thank You.

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [15 February 2023 18:52 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/2 "2023-02-15T18:52:09Z")

</div>

So where is the problem? Take a split node and specify 10 in the len field, which creates arrays with 10 elements.

```auto
[
    {
        "id": "bb68ecc0093a7092",
        "type": "split",
        "z": "7e6af0015415146d",
        "name": "split Array",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": "10",
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 620,
        "y": 1240,
        "wires": [
            [
                "117ade0db50aca7c"
            ]
        ]
    },
    {
        "id": "117ade0db50aca7c",
        "type": "delay",
        "z": "7e6af0015415146d",
        "name": "",
        "pauseType": "delay",
        "timeout": "15",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 810,
        "y": 1240,
        "wires": [
            []
        ]
    }
]

```

---

<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:** [15 February 2023 19:03 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/3 "2023-02-15T19:03:12Z")

</div>

I think the delay should be rate limit 1 per 15 seconds, not delay  
e.g.

```auto
[{"id":"5b2879f291e75a35","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":4680,"wires":[["395a7600299bef98"]]},{"id":"395a7600299bef98","type":"function","z":"da8a6ef0b3c9a5c8","name":"create test array","func":"let count = 0;\nmsg.payload = [...Array(150)].map(() => {\n count++;\n return count;\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":4680,"wires":[["a47d1a71fb835c99"]]},{"id":"a47d1a71fb835c99","type":"split","z":"da8a6ef0b3c9a5c8","name":"","splt":"\\n","spltType":"str","arraySplt":"10","arraySpltType":"len","stream":false,"addname":"","x":430,"y":4680,"wires":[["4fdf9ca73fc4af33"]]},{"id":"4fdf9ca73fc4af33","type":"delay","z":"da8a6ef0b3c9a5c8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":580,"y":4680,"wires":[["930b846aad428369"]]},{"id":"930b846aad428369","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 233","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":4680,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![zakha001](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zakha001](https://discourse.nodered.org/u/zakha001)\
**Post date:** [15 February 2023 19:41 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/4 "2023-02-15T19:41:40Z")

</div>

Thanks for the reply.

I used the split node before but I would need to upload the shorter arrays after 15 seconds each. The split node would split the large array into shorter arrays but I was unable to add a delay of 15 seconds. The shorter arrays need to finally end up in the following node: 'node-red-contrib-thingspeak42'.

I want the 'Thingspeak42' node to receive a shorter array of 10 values from the previous nodes (which split the larger array) after a delay of 15 seconds.

 ![Node-red_Thingspeak](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/42b3c5790e8123524efff682df9b3f88d72c1b68.jpeg)

---

<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:** [17 February 2023 16:58 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/5 "2023-02-17T16:58:17Z")

</div>

> [@zakha001](#):
>
> I would need to upload the shorter arrays after 15 seconds each

Did you try a delay node in Rate Limit mode as suggested by @E1cid.  
If that doesn't work for you please explain better what you need.

---

<div class="post-metadata">

**Author:** ![zakha001](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zakha001](https://discourse.nodered.org/u/zakha001)\
**Post date:** [17 February 2023 18:07 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/6 "2023-02-17T18:07:28Z")

</div>

No, I have not been able to test it out yet, will do it on Monday. However, I have already tried adding the delay node in the Rate Limit mode but it did not work at that time. Maybe I did not configure it correctly. I will try @E1cid's method and let you guys know afterward.

I have another question regarding this: Can I use the python-function node and write a code that could take the Array of 150 values, split it into shorter 15 arrays of 10 values each, and send each shorter array after a 15-second delay? Will the python-function node work like this?

---

<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:** [17 February 2023 21:51 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/7 "2023-02-17T21:51:33Z")

</div>

> [@zakha001](#):
>
> Can I use the python-function node

Why bother? The Delay node in Rate Limit mode configured for 1 message every 15 seconds will only pass 1 message every 15 seconds, which is exactly what you want isn't it? If it doesn't work then show us how you have configured it. Test the node first with an Inject, Delay and Debug and play with the settings so you can see what it does.

---

<div class="post-metadata">

**Author:** ![zakha001](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zakha001](https://discourse.nodered.org/u/zakha001)\
**Post date:** [20 February 2023 19:34 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/8 "2023-02-20T19:34:15Z")

</div>

@E1cid It worked, however I had to add the join with split node.

---

<div class="post-metadata">

**Author:** ![zakha001](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zakha001](https://discourse.nodered.org/u/zakha001)\
**Post date:** [20 February 2023 19:35 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/9 "2023-02-20T19:35:26Z")

</div>

@Colin Yes, you were right. I did not actually have to use the python function block. I did it with Join and Split nodes.

---

<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:** [20 February 2023 20:06 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/10 "2023-02-20T20:06:13Z")

</div>

> [@zakha001](#):
>
> however I had to add the join with split node

That is because you Array of 150 is actually an object, missed that in your OP photo. Happy you found a solution.

---

<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 March 2023 20:06 UTC](https://discourse.nodered.org/t/split-an-array-of-150-values-into-shorter-15-arrays-of-10-values/75247/11 "2023-03-06T20:06:24Z")

</div>

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