Javascript (Node-RED) – Search Array with Objects

I’m looking for performant solution to search a MAC adress inside an array with objects.

So here my example array that is coming in to the function node in my Node-RED.

[
    [
        {
            "hostname": "PC1",
            "mac": "aa:aa:aa:xx:xx:xx",
            "online": true
        },
        {
            "hostname": "PC2",
            "mac": "bb:bb:bb:xx:xx:xx",
            "online": true
        },
        {
            "hostname": "PC3",
            "mac": "cc:cc:cc:xx:xx:xx",
            "online": false
        }
    ]
]

This array is much much bigger ofc. I had a solution with iterating through the whole array with a for loop. I hope there is a much more performant solution.

Already tried to use code snippets from here (www.digitalocean.com/community/tutorials/js-array-search-methods-de) without success because my array has a child array (at least I think that this is the problem).

My output of anything should be a variable that tells me if the mac is online or not.

I hope someone can help me out.

Thank you in advance.

Read more here: Source link