Resolved - Images in ProGallery not always appearing (on.ready related?)

Hi,
I currently have an issue where the images inside a Wix Pro Gallery don’t always appear (both editor/live mode) and I suspect it has something to do with the data not being ready to be manipulated. What I mean by that is I’m trying to randomize the order of the photos displayed and sometimes that gallery will be blank. I’ve noticed by logging the info that sometimes the items array = 0, before things start to get randomized.

The following code:

$w.onReady( () => {
    $w("#dataset3").onReady(() => {
       let items = $w("#gallery1").items;
       //console.log(items)
       items = shuffle(items);
       $w("#gallery1").items = items;
    });
});
export function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
 const j = Math.floor(Math.random() * (i + 1));
   [array[i], array[j]] = [array[j], array[i]];
}
return array;
}

Since the Pro Gallery is below the fold or the page is not done loading, is there a way to put some sort of condition to ensure the ITEMS variable will contain the images before the shuffling function proceeds?

Thanks for your time
Webpage: emunations.com/gliden64

It seems to have resolved via this

  ...
      wixData.query("xxxxxx")
        .eq("title", "xxxxxxx")
        .find()
        .then((results)=> {
 let items = results.items[0].gallery;   
        items = shuffle(items);
        $w("#gallery1").items = items;  
    });   
})
export function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
 const j = Math.floor(Math.random() * (i + 1));
   [array[i], array[j]] = [array[j], array[i]];
}
return array;
}