I have an array of objects (one property is the hostname of the device) stored in my global context.
Now I would like to ping some of them and store the value of roundtrip in ms to it's to the related object.
What is the best solution to do so?
I read a lot about .map()
and .forEach()
and the fact that I don't need to recreate the whole context array, but just add that property to an object in the array confuses me on how to do it best.
Moreover, I am a bit worried about doing that every let's say 60s on my rpi4.
Is it safe to just itter over the array with an for loop and add that property where the hostname matches?
let hosts = global.get('hosts');
for (let i = 0; i < hosts.length; i++) {
var e = hosts[i];
if(e.host === msg.topic){
global.set('hosts['+i+'].ping', msg.payload)
}
}