# Filter out data from a (changing) array

**URL:** <https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891>\
**Category:** General\
**Created:** [8 February 2023 15:00 UTC](https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891 "2023-02-08T15:00:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TommyTommy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tommytommy/32/75773_2.png) [@TommyTommy](https://discourse.nodered.org/u/TommyTommy)\
**Post date:** [8 February 2023 15:00 UTC](https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891/1 "2023-02-08T15:00:30Z")

</div>

Hi,

I have an Array that refreshes every 60 seconds, the array looks like this picture

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

I know i can grab a specific postion using the change node and "payload[0].VR[0]" for example, the problem is that the data in the array seems to be randomly ordered. If i want to read the data (VR) with the ID of "ST: "158", how would i go about this?

Here is the array

> [{"ID":"1","TS":"1675867974","ST":"157","VR":[0]},{"ID":"1","TS":"1675867974","ST":"158","VR":[0]},{"ID":"1","TS":"1675867974","ST":"159","VR":[0]},{"ID":"1","TS":"1675867974","ST":"163","VR":[0]},{"ID":"1","TS":"1675867974","ST":"223","VR":[0]},{"ID":"1","TS":"1675867974","ST":"224","VR":[0]},{"ID":"1","TS":"1675867974","ST":"231","VR":[0]},{"ID":"1","TS":"1675867974","ST":"337","VR":[0]},{"ID":"1","TS":"1675867974","ST":"1","VR":[55]},{"ID":"1","TS":"1675867974","ST":"26","VR":[415]},{"ID":"1","TS":"1675867974","ST":"32","VR":[419]},{"ID":"1","TS":"1675867974","ST":"28","VR":[360]},{"ID":"1","TS":"1675867974","ST":"98","VR":[556]},{"ID":"1","TS":"1675867974","ST":"106","VR":[570]},{"ID":"1","TS":"1675867974","ST":"103","VR":[516]},{"ID":"1","TS":"1675867974","ST":"195","VR":[57]},{"ID":"1","TS":"1675867974","ST":"196","VR":[7600]},{"ID":"1","TS":"1675867974","ST":"197","VR":[0]},{"ID":"1","TS":"1675867974","ST":"34","VR":[456]},{"ID":"1","TS":"1675867974","ST":"107","VR":[133]},{"ID":"1","TS":"1675867974","ST":"246","VR":[0]},{"ID":"1","TS":"1675867974","ST":"286","VR":[372]},{"ID":"1","TS":"1675867974","ST":"243","VR":[0]},{"ID":"1","TS":"1675867974","ST":"244","VR":[0]}]

Thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 February 2023 15:30 UTC](https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891/2 "2023-02-08T15:30:06Z")

</div>

Hello @TommyTommy,

Here is one way to do it

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/edecff6b9d6b3f07c2b5fc9415e6e584ffa2982b.jpeg)

```auto
[{"id":"7b933e12b9945c08","type":"inject","z":"ac3483be8df714b3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"157\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"158\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"159\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"163\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"223\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"224\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"231\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"337\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"1\",\"VR\":[55]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"26\",\"VR\":[415]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"32\",\"VR\":[419]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"28\",\"VR\":[360]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"98\",\"VR\":[556]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"106\",\"VR\":[570]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"103\",\"VR\":[516]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"195\",\"VR\":[57]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"196\",\"VR\":[7600]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"197\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"34\",\"VR\":[456]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"107\",\"VR\":[133]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"246\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"286\",\"VR\":[372]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"243\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"244\",\"VR\":[0]}]","payloadType":"jsonata","x":470,"y":100,"wires":[["1596ed850731f543"]]},{"id":"1bb7db14a735b5b5","type":"debug","z":"ac3483be8df714b3","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":100,"wires":[]},{"id":"1596ed850731f543","type":"function","z":"ac3483be8df714b3","name":"function 1","func":"let newmsg = {}\nfor (let i=0; i<msg.payload.length; i++) {\n newmsg.payload = msg.payload[i]\n node.send(newmsg)\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":100,"wires":[["719f30f7cda9d490"]]},{"id":"719f30f7cda9d490","type":"switch","z":"ac3483be8df714b3","name":"","property":"payload.ST","propertyType":"msg","rules":[{"t":"eq","v":"158","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":770,"y":100,"wires":[["1bb7db14a735b5b5"]]}]

```

I have moved the check for ST == 158 out of the function into a switch node, but you could test it inside the function node for loop.

---

<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:** [8 February 2023 16:07 UTC](https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891/3 "2023-02-08T16:07:33Z")

</div>

You can also do it in a change node with JSONata  
here are some examples.

```auto
[{"id":"9c588cf1cc587faa","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"158","payload":"[{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"157\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"158\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"159\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"163\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"223\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"224\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"231\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"337\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"1\",\"VR\":[55]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"26\",\"VR\":[415]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"32\",\"VR\":[419]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"28\",\"VR\":[360]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"98\",\"VR\":[556]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"106\",\"VR\":[570]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"103\",\"VR\":[516]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"195\",\"VR\":[57]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"196\",\"VR\":[7600]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"197\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"34\",\"VR\":[456]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"107\",\"VR\":[133]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"246\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"286\",\"VR\":[372]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"243\",\"VR\":[0]},{\"ID\":\"1\",\"TS\":\"1675867974\",\"ST\":\"244\",\"VR\":[0]}]","payloadType":"json","x":110,"y":4800,"wires":[["f97fee70ff26c1fd","ceda5fbce2e10e3a","8c828c73f394245e"]]},{"id":"f97fee70ff26c1fd","type":"change","z":"da8a6ef0b3c9a5c8","name":"return object","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[ST =\"158\"]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":4760,"wires":[["1f51ffb244896559"]]},{"id":"ceda5fbce2e10e3a","type":"change","z":"da8a6ef0b3c9a5c8","name":"return VR[0]","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[ST =\"158\"].VR[0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":4820,"wires":[["4df95968b2f05ab2"]]},{"id":"8c828c73f394245e","type":"change","z":"da8a6ef0b3c9a5c8","name":"Search with topic","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[ST =$$.topic]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":4880,"wires":[["5baa8e74f31659e2"]]},{"id":"1f51ffb244896559","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 231","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":4760,"wires":[]},{"id":"4df95968b2f05ab2","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 232","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":4820,"wires":[]},{"id":"5baa8e74f31659e2","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 233","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":4880,"wires":[]}]

```

---

<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:** [22 February 2023 16:07 UTC](https://discourse.nodered.org/t/filter-out-data-from-a-changing-array/74891/4 "2023-02-22T16:07:50Z")

</div>

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