Split / loop array to get correct value

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 :


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

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
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.

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.