Gallery pro bug

Hi, I have a very simple setup - I have 2 texts and 2 gallery pros on my page, if I try to change the items in my gallery when it is inside an object in an array - it doesn’t work. Here is an example:

var myArray = [
{ item : $w ( ‘#text1’ ), gallery : $w ( ‘#gallery1’ )},
{ item : $w ( ‘#text2’ ), gallery : $w ( ‘#gallery2’ ) }
]

$w . onReady ( function () {
myArray [ 0 ]. item.text = “hello” ; //this works
myArray [ 0 ]. gallery.items = [] // this doesn’t work
console . log ( “hi” ); // this works
});

In contrust this does work:

//this all works
var myArray = [
{ item : $w ( ‘#text1’ ), gallery : $w ( ‘#gallery1’ )},
{ item : $w ( ‘#text2’ ), gallery : $w ( ‘#gallery2’ ) }
]
$w . onReady ( function () {
myArray [ 0 ]. item.text = “hello” ;
$w ( ‘#gallery1’ ). items = [];
console . log ( “hi” );
});

And finaly the wierdest:
var myArray = [
{ item : $w ( ‘#text1’ ), gallery : $w ( ‘#gallery1’ )},
{ item : $w ( ‘#text2’ ), gallery : $w ( ‘#gallery2’ ) }
]
$w . onReady ( function () {
myArray [ 0 ]. item.text = “hello” ; //this works
myArray [ 0 ]. gallery.items = [] // this doesn’t work
$w ( ‘#gallery1’ ). items = []; //now this also doesn’t work
console . log ( “hi” );//this works

What am I doing wrong?

Front-End-Example:

$w.onReady(()=> {   
    let gallaryItems = [
        {   
            type: "Image", 
            src: "wix:image://v1/b25591_2790fd3a23db403793dbf2c3c1c62723~mv2_d_3000_1946_s_2.jpg/Add%20a%20Title.jpg#originWidth=3000&originHeight=1946",
            description: "Describe your image",
            title: "Add a Title",
            height: 1946,
            width: 300,
        }
    ]
    $w('#gallery1').items = [];
    $w('#gallery1').items = gallaryItems;
});

Thank you for your replay.
This does work but I would like to use the " gallaryItems" variable as a global variable so I can use it in multiple functions. Is that posible?

Maybe i do not understand what you are trying to achieve.
Can you make an example?
What is exactly your aim?