Hello,
Can someone help me get some code for creating a randomized repeater that will only show ONE random professional from my professional database? I have gone through multiple codes given out on here, and they either aren’t working, or will repeat out ALL professionals in my database randomly. I want only one to show, and for it to update randomly every time the page is re-loaded.
Here is the code i’m using that successfully randomizes the professionals, but I need it to only show one at a time:
import wixData from ‘wix-data’;
$w.onReady( function () {
//get the collection records
wixData.query(“Professionals”)
.find()
.then((result) => {
const shuffledArray = shuffleArray(result.items);
//add the shuffled array data to then repeaters
$w(‘#meetTheTeamBox’).data = shuffledArray;
})
. catch ((err) => {
let errorMsg = err;
});
});
//random array index
function getRandomIndex(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
//shuffle array data
function shuffleArray(dataArray){
for(let i = dataArray.length - 1; i > 0; i–){
let index = getRandomIndex(0, i);
const temp = dataArray[i];
dataArray[i] = dataArray[index];
dataArray[index] = temp;
}
return dataArray;
}
Thanks in advance!