I have an array of objects containing a field duration that specifies the duration that the Object should stay visible.
Each Object of array has it's own duration.
So i want to make each object appear after another with the help of setTimout.
Something like this : (onClick)
const playScenes = () => {
const cpScenes = [...scenes];
for(let i; i < cpScenes.length;i++){
const timer = setTimeout(() => {
showScene(cpScenes[i]); //Show the current scene
}, cpScenes[i].duration); //Time changes automatically
}
clearTimeout(timer);
};
The way am thinking about this is that setTimeout should block execution of for loop and then run after specified time and then the loop continues..