When I try to execute by for loop & setTimeout method then got the output undefined. Then i tried to below method
var alphAbet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
setTimeout(function loop() {
console.log(alphAbet.shift());
if (alphAbet.length){
setTimeout(loop, 3000);
}
}, 3000);
From A to Z all letters execute after 3 seconds. But based on the condition letter A will not take any time.
Aucun commentaire:
Enregistrer un commentaire