need help with looping

Hi there,

Can someone help with this code please, the code works fine as it is. I have 2 images in CMS gallery field and I have image element in the repeater which is populated by the first image from CMS gallery field.

I would like to change this code so the image element in the repeater is updated with the 2nd image form cms gallery field after 2 second and continously loops.

In this case my dataset = dataset 1
repeater = repeaterDesigns
CMS media gallery = mediagallery
image element in repeater = ThumbnailFromGallery

Thank you
Ravinder

$w(‘#dataset1’).onReady(() => {
//use the onItemready function for the repeater
$w(‘#repeaterDesigns’).onItemReady(($Item, ItemData) => {
//Get the media gallery field (an array of images)
const mediagallery = ItemData.mediagallery;

        //Check if the mediaGallery field is populated and is an array
        if (Array.isArray(mediagallery) && mediagallery.length > 0) {
            //Get the first image from the gallery
            const firstImage = mediagallery[0].src;
            //const next = mediagallery[1].src;

            $Item('#ThumbnailFromGallery').src = firstImage;

        } else {
            //Handle cases where the media gallery is empty or invalid
            console.warn('Media gallery is empty or not an array for item:', ItemData)
        }

    });
});