Turn off all lights except the ones in array

Found this script in the old forum:
let devices = await Homey.devices.getDevices();
function anyLightOn(devices) {
let result = false;
_.some(devices, device => {
if (device.class === ‘light’ && device.state.onoff) {
result = true;
return result;
return result;
return anyLightOn(devices)

I would like something similar but I would lika to add an array to exclude som lights and is it possible to temporarilly store all lights turned off in a variable to make a check if light really turned off?
I have some lights via 433MHz power plug and some ZigBee.

I’ve tried something similar bellow but it doesn’t work as expected:
let devices = await Homey.devices.getDevices();

var DeviceNames = [
    "Kitchentable - Right",
    "Kitchentable - Middle",
    "Kitchentable - Left",
    "Lightstripp hall",
    "Master bedroom - Spotlights",
    "Master bedroom - Window lights",
    "Master bedroom - Sandra",
    "Master bedroom - Markus",
    "Second floor - Hall",
    "Livingroom - Window lights",
    "Livingroom lights"
    DeviceNames.forEach(function(element) {

   _.forEach(devices, device => {
        if(device.class != 'light') return;
            if(!device.state.onoff) return;
                if(!device.name != element) return;        
                        device.setCapabilityValue('onoff', false);
return true