I'm creating a webpage on which I want to hide/show certain divs. To do this, I created a for-loop to change the style.display to `none` or `block`. Using the same for-loop I simultaneously want to update an array.

When I hide the div, the array should be empty. But when I show the div it should contain values listed below `[65, 59, 80, 81, 56, 55]`.

My issue is; the array updates inside the loop, but not outside. Why is it not updating the array outside the loop?

**The output should be an updated array which can be used outside the for-loop.**

```
var array1 = [];
function hideRightBlock() {
    var x = document.getElementById("text_box_right");
    if (x.style.display === "none") {
        x.style.display = "block";
        var array1 = [65, 59, 80, 81, 56, 55];
    } else {
        x.style.display = "none";
        var array1 = [];
    }
}

```