Help - length (object)

I want to enum/count each item (object) in DEVICES but lenght does not work... Can I be missing something please?

Capture

context.global.getDomainDevices = function(domain){
    //Gets all devices from a specific domain
    node.warn("getDomainDevices: Starting->" + domain);
    devices = global.get("DEVICES");
    ret="";
    for (i=0; i<devices.length; i++){
        node.warn("getDomainDevices: Item->" + devices[i]);
        if (devices[i].domain === domain){
            node.warn("getDomainDevices: Found->" + devices[i]);
            //It is part of this domain
            if (ret !== "" ){
                ret += "," + devices[i];
            }else{
                ret = devices[i];
            }
        }
    }
    node.warn("getDomainDevices: Result->" + ret);
    return ret;
}

Objects don't have a length property - only Arrays do (and Strings, but that's not relevant here).

To loop over its contents, you can do:

for (const key in devices) {
   const device = devices[key];
  //...
}
3 Likes

Thank you!

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