# Search Array for name, SSID or MAC

**URL:** <https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560>\
**Category:** General\
**Created:** [27 September 2021 09:13 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560 "2021-09-27T09:13:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [27 September 2021 09:13 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/1 "2021-09-27T09:13:01Z")

</div>

How or where do I search a array? Using the Unifi Node looking for RogueAPs mac and signal strength.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/ef6cc7b2931bd26f8bd54136a5d5ee1f10d1eb25.png)

---

<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:** [27 September 2021 09:16 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/2 "2021-09-27T09:16:59Z")

</div>

Use a function node and the `filter` function

Example: [javascript - Filter array of objects with another array of objects - Stack Overflow](https://stackoverflow.com/questions/31005396/filter-array-of-objects-with-another-array-of-objects)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 September 2021 11:36 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/3 "2021-09-27T11:36:17Z")

</div>

Or an equivalent using a change node and JSONata 😀

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [28 September 2021 20:30 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/4 "2021-09-28T20:30:30Z")

</div>

thanks how do I find the name of the array? In the example its myArray , my output not sure suspect I need to put this into x to name it?

---

<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:** [28 September 2021 21:43 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/5 "2021-09-28T21:43:42Z")

</div>

The name of the array, according to your screenshot is msg.payload

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.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

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

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [5 October 2021 01:48 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/6 "2021-10-05T01:48:21Z")

</div>

Thanks and yes got that and can filter with a change node. What I want to figure out is searching the combined output for new bssid or oui for example from the combined output of the array (msg.payload). Looking for new bssid or oui not seen before. So this means I want to search the array for new unknown devices? Hopefully this makes sense.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [5 October 2021 15:10 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/7 "2021-10-05T15:10:12Z")

</div>

So from what you say you want to identify any device not yet seen. The example Steve-Mcl pointed at provides the answer. You have to keep an array of known devices and compare the two arrays. From Stack Overflow (plus a bit),

```auto
const filterObjectArray = (arr, filterArr, filterProperty) => (
    arr.filter(el =>
        filterArr.every(f =>
            f[filterProperty] !== el[filterProperty]
        )
    )
)

```

Then

```auto
let knownDevices = context.get('knownDevices', 'file') || []
let deviceArray = msg.payload

let unknownDevices = filterObjectArray(deviceArray, knownDevices, 'bssid')

.... do what ever you want with array of unknown devices

// Add unknown devices to known devices
knownDevices.push(...unknownDevices)

context.set('knownDevices', knownDevices, 'file')

```

The bssid should be unique so this should cover new oui properties also, but if you want to identify new oui properties as a separate check, rinse and repeat above using 'oui' as the `filterProperty`

You can do something similar to find non optimum signal strength

```auto
const minSignal = -40
const maxSignal = 30

const result = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)

```

Google is your friend but check the nodered docs for Node-RED and something like MDN Docs for javascript

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [6 October 2021 06:39 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/8 "2021-10-06T06:39:22Z")

</div>

Thanks Buckskin so I have added to a function node on message.

So this adds the knowdevices to unknown and does it compare?

```auto
knownDevices.push(...unknownDevices)

context.set('knownDevices', knownDevices, 'file')

```

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

Tried to review each portion of the code added // expressions/operators

So this should only return results between 30 to -40

```auto
device.signal less than minSignal || device.signal more than maxSignal

```

```auto
const minSignal = -40
const maxSignal = 30

```

So the out out looks the same prior to the function node / javascript, what am I misunderstanding?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [6 October 2021 12:33 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/9 "2021-10-06T12:33:25Z")

</div>

The use of the functions were examples and provide different results. You haven't added the results to the msg.

If you are after both unknown devices and bad signals then try

> let msg.unknownDevices = unknownDevices

to get an array of unknownDevices, and after

```auto
const result = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)`

```

use

```auto
let msg.badSignal = result

return msg

```

You will then have to monitor `msg.unknownDevices` and `msg.badSignal` instead of `msg.payload`. Use a debug node set to 'complete message object'

If you just want devices with a bad signal just use

`let msg.payload = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)`

Note: change `minSignal` & `maxSignal` values to whatever values you are actually defining as bad

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [6 October 2021 19:28 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/10 "2021-10-06T19:28:20Z")

</div>

Thanks but still not understanding, could you give me a complete example of any device with its bssid, a signal of say 30 max, -40 min to then give a msg output (will use (MQTT). What I am trying to do is detect any device not on the wireless ie not connected and beaconing that has a signal between 30-40 with its BSSID to say that there is a unknown device close by? TIA.

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [12 October 2021 04:00 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/11 "2021-10-12T04:00:18Z")

</div>

Thanks [Buckskin](https://discourse.nodered.org/u/Buckskin)

---

<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:** [11 December 2021 04:00 UTC](https://discourse.nodered.org/t/search-array-for-name-ssid-or-mac/51560/12 "2021-12-11T04:00:51Z")

</div>

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