So here's the issue I'm facing with my function:
function toggleAgenteMarkerSingolo(i) {
console.log(lines_agenti); //this console log displays the array correctly
console.log(lines_agenti[i]); //but this one shows undefined
if (!lines_agenti[i].getVisible()) {
lines_agenti[i].setVisible(true);
visible = true;
} else {
lines_agenti[i].setVisible(false);
visible = false;
}
return visible;
}
In the code above, after checking the contents of the array in the first "console.log", the second one doesn't provide the expected output.
The functionality within the function is not working as intended due to this problem.
Below is where the function is called:
checkbox.addEventListener('click', (function(i) {
console.log(i);
visible = toggleAgenteMarkerSingolo(i);
if(visible == true){
//do something
}else{
//do something
}
})(i));
This section is part of a larger function that dynamically creates checkboxes using DOM manipulation.
The global variable "lines_agenti" is declared at the beginning of the script:
<script>
var lines_agenti = [];
[...]
Your assistance in resolving this issue would be greatly appreciated. Thank you.
I have included a screenshot of the console for reference.https://i.sstatic.net/mkUcF.png