# Get data from array, only when is\_wired is true

**URL:** https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607
**Category:** Dashboard
**Created:** [16 August 2020 13:26 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607 "2020-08-16T13:26:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Doebe](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@Doebe](https://discourse.nodered.org/u/Doebe)
#### Post date: [16 August 2020 13:26 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/1 "2020-08-16T13:26:56Z")

</div>

Hi,

I want to extract certain information from an array  
I get the connection data of my devices from  
node-red-contrib-unifi / ClientDevices  
This connection data is send in an array.  
I use node-red-contrib-splitter to split the array, no I have about 26 array elements.  
Here is an example of 2 array elements.

```auto
"_msgid": "6b6a97a1.12b788",
	"payload": [
		{
			"site_id": "some_data",
			"assoc_time": 1597038040,
			"latest_assoc_time": 1597524359,
			"oui": "Logitech",
			"user_id": "some_data",
			"_id": "some_data",
			"mac": "some_data",
			"is_guest": false,
			"first_seen": some_data,
			"last_seen": some_data,
			"is_wired": false,
			"hostname": "HarmonyHub",
			"use_fixedip": true,
			"network_id": "some_data",
			"fixed_ip": "192.168.0.153",
			"noted": false,
		},
		{
			
			"is_guest": false,
			"first_seen": 1562066511,
			"last_seen": 1597569302,
			"is_wired": true,
			"use_fixedip": true,
			"network_id": "some_data",
			"fixed_ip": "192.168.0.8",
			"noted": true,
			"usergroup_id": "some_data",
			"name": "Homeseer",
			"fingerprint_override": true,
			
		}
	]
}

```

Now I want to check the array elemnt and see if "is\_wired": true  
If this is true then I want to get the value of "hostname": "HarmonyHub"  
And copy this in a new array. I want to check this for al array elements.  
So I get an array output of al hostnames connected with is\_wired : false  
Something like :  
"payload": [  
{"HarmonyHub" , “iphone” , “android phone” , “google home” }  
If I have a list of al devices connected with the wifi. I want to send the to  
node-red-node-ui-list  
to create a list of all devices on the Node-red dashboard.

Now my question how do I extract the correct data from the array using the function node.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [16 August 2020 14:18 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/2 "2020-08-16T14:18:14Z")

</div>

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [16 August 2020 17:09 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/3 "2020-08-16T17:09:00Z")

</div>

> [@Doebe](#):
>
> ```auto
> "name": "Homeseer",
> "fingerprint_override": true,
> 		
> }
> ]
> 
> ```

Your objects in the array should not end with a comma

why not use the core `split` node? then process each array element and if it is one where you want the data, put the data into a flow variable array. When the last msg comes thru, then get the data brom the flow variable and send it to the ui\_list.

---

<div class="post-metadata">

### Author: ![Doebe](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@Doebe](https://discourse.nodered.org/u/Doebe)
#### Post date: [16 August 2020 17:37 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/4 "2020-08-16T17:37:21Z")

</div>

The comma is ther because i removed some data of the array.  
i have use splitter and have al the data in seperate messages.  
but i thought it would be cleaner to use something a funtion .  
with something like

array.forEach(function (where is\_wired = false) do  
msg.payload = msg.payload + hostname + ","

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [16 August 2020 18:08 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/5 "2020-08-16T18:08:17Z")

</div>

Look at array filter function.

Something like...

```auto
var filtered = msg.payload.filter(e => e.is_wired === true)
msg.payload = filtered

```

That will return an array of items that are is\_wired == true

Note, no spitting necessary, the payload is an array, just filter it.

update...

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/80ba0357aea808973818b31f51561e0bae254db3.png)

```auto
[{"id":"a31f7aa.4de2b88","type":"function","z":"486d43a.6a75dbc","name":"filter is_wired","func":"var filtered = msg.payload.filter(e => e.is_wired === true)\nmsg.payload = filtered\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":870,"y":160,"wires":[["441a8c64.a3ad54","1e46c4ce.30b14b"]]},{"id":"9ebcb1a0.345ab","type":"inject","z":"486d43a.6a75dbc","name":"faking your data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"site_id\":\"some_data\",\"assoc_time\":1597038040,\"latest_assoc_time\":1597524359,\"oui\":\"Logitech\",\"user_id\":\"some_data\",\"_id\":\"some_data\",\"mac\":\"some_data\",\"is_guest\":false,\"first_seen\":\"some_data\",\"last_seen\":\"some_data\",\"is_wired\":false,\"hostname\":\"HarmonyHub1\",\"use_fixedip\":true,\"network_id\":\"some_data\",\"fixed_ip\":\"192.168.0.153\",\"noted\":false},{\"site_id\":\"some_data\",\"assoc_time\":1597038040,\"latest_assoc_time\":1597524359,\"oui\":\"Logitech\",\"user_id\":\"some_data\",\"_id\":\"some_data\",\"mac\":\"some_data\",\"is_guest\":false,\"first_seen\":\"some_data\",\"last_seen\":\"some_data\",\"is_wired\":true,\"hostname\":\"HarmonyHub2\",\"use_fixedip\":true,\"network_id\":\"some_data\",\"fixed_ip\":\"192.168.0.153\",\"noted\":false},{\"is_guest\":false,\"first_seen\":1562066511,\"last_seen\":1597569302,\"is_wired\":true,\"use_fixedip\":true,\"network_id\":\"some_data\",\"fixed_ip\":\"192.168.0.8\",\"noted\":true,\"usergroup_id\":\"some_data\",\"name\":\"Homeseer\",\"fingerprint_override\":true,\"hostname\":\"Homeseer1\"},{\"is_guest\":false,\"first_seen\":1562066511,\"last_seen\":1597569302,\"is_wired\":false,\"use_fixedip\":true,\"network_id\":\"some_data\",\"fixed_ip\":\"192.168.0.8\",\"noted\":true,\"usergroup_id\":\"some_data\",\"name\":\"Homeseer\",\"fingerprint_override\":true,\"hostname\":\"Homeseer2\"}]","payloadType":"json","x":640,"y":160,"wires":[["a31f7aa.4de2b88","410b4594.b07b8c"]]},{"id":"441a8c64.a3ad54","type":"debug","z":"486d43a.6a75dbc","name":"Filtered data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":160,"wires":[]},{"id":"1e46c4ce.30b14b","type":"debug","z":"486d43a.6a75dbc","name":"first items hostname","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload[0].hostname","targetType":"msg","statusVal":"payload[0].hostname","statusType":"auto","x":1100,"y":220,"wires":[]},{"id":"410b4594.b07b8c","type":"debug","z":"486d43a.6a75dbc","name":"All data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":100,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Doebe](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@Doebe](https://discourse.nodered.org/u/Doebe)
#### Post date: [16 August 2020 19:08 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/6 "2020-08-16T19:08:52Z")

</div>

Thanks i give it a try.

---

<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: [15 September 2020 19:08 UTC](https://discourse.nodered.org/t/get-data-from-array-only-when-is-wired-is-true/31607/7 "2020-09-15T19:08:57Z")

</div>

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