How can i set duration for "ArrayList" which shuffles after few seconds in a loop? The code below shuffle text after every page refresh.
// For full API documentation, including code examples, visit https://wix.to/94BuAAs $w.onReady(function () { });
const ArrayList = [ 'Live', 'Work', 'Play', ];
$w.onReady(function(){ const randomIndex = Math.floor(Math.random() * (ArrayList.length)); $w('#text33').text = ArrayList[randomIndex];
return ArrayList; });
Thank you!
Try:
const ArrayList = [ 'Live', 'Work', 'Play',];
const interval = 3000;// milliseconds
setInteraval(() => shuffleArray , interval);
function shuffleArray() {
for (let i = array.length - 1; i > 0; i--) {
const random = Math.floor(Math.random() * (i + 1));
[ArrayList[i], ArrayList[random] = [ArrayList[random], ArrayList[i]];
}
}