I am building an app with Javascript and OpenLayers and while it's going fairly well, I am stuck at what I feel could be an easy problem for someone experienced.
Here is part the code where the problem lives :
 const baseLayerElementsRight = document.querySelectorAll(
        '[name="baseLayerRadioButtonRight"]'
    );
    let layerRender = {};
    for (let baseLayerElementRight of baseLayerElementsRight) {
        baseLayerElementRight.addEventListener(
            'change',
            function() {
                let baseLayerElementValueRight = this.value;
                layerGroupRight.getLayers().forEach(function(element) {
                    let baseLayerNameRight = element.get('title');
                    element.setVisible(
                        baseLayerNameRight === baseLayerElementValueRight
                    );
                    let elementVisibility = element.get('visible');
                    if (elementVisibility) {
                        layerRender = element;
                        console.log(layerRender);
                    }
                });
            },
            false
        );
    }console.log(layerRender)
So Basically, I need to apply a method on the "layerRender" object variable outside of the event callback and I am quite new to programming and I struggle to find a solution to access the variable value
The console.log in the callback's event output the Object I want everytime I click on a given radio type input, but the console.log outisde it outputs an empty Object and of course don't update everytime I the event is happening.
How could I do to access the layerRender value outside of the callback?
Thanks a lot
 
    