# Split / loop array to get correct value

**URL:** <https://discourse.nodered.org/t/split-loop-array-to-get-correct-value/16929>\
**Category:** General\
**Created:** [20 October 2019 17:27 UTC](https://discourse.nodered.org/t/split-loop-array-to-get-correct-value/16929 "2019-10-20T17:27:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [20 October 2019 17:27 UTC](https://discourse.nodered.org/t/split-loop-array-to-get-correct-value/16929/1 "2019-10-20T17:27:51Z")

</div>

hi guys i hope you can help me out here  
first i want to make a flow that outputs all wifi connected devices  
i use Unifi access point and my Unifi node is working OK.  
the debug output of my unifi node is :

> array[1]
> 
> 0: array[20]  
> [0 … 9]  
> 0: object  
> oui: "SamsungE"  
> is\_guest: false  
> first\_seen: 1551101353  
> last\_seen: 1571576015  
> is\_wired: false  
> hostname: "Galaxy-Note9"  
> duration: 9893563  
> tx\_bytes: 362744764723  
> tx\_packets: 276752825  
> rx\_bytes: 21176276344  
> rx\_packets: 133682433  
> wifi\_tx\_attempts: 0  
> tx\_retries: 0

I just want to make a function that loops the complete array and finds ( in this example ) the "Galaxy-Note9"  
the size of the array is sometimes sort and sometimes long depending how manay wifi devices are connected.  
I did not manage to made that loop so i hope someone can help me out here.

many many thanks  
menno

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [20 October 2019 17:30 UTC](https://discourse.nodered.org/t/split-loop-array-to-get-correct-value/16929/2 "2019-10-20T17:30:49Z")

</div>

Hi Menno,  
Take a look at the array functions listed on MDN, array.filter specifically: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)  
That one can likely do what you need. If you’re interested in all items from that array instead, look at the split node, followed by a switch for specific fine-tuning.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 October 2019 18:16 UTC](https://discourse.nodered.org/t/split-loop-array-to-get-correct-value/16929/3 "2019-10-20T18:16:36Z")

</div>

You can use a change node

set `msg.payload`  
to j(sonata) expression : `payload.*[$contains($.hostname,"Galaxy-Note9")]`

and you can use a shorter search string if you want (or even regular expressions).  
It will output the object when found.
