标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:JavaScript : For loop with timeout10 answersI'm trying to make a text display in DOM from a->b->c->d->e with a 1-second delay between each alphabet using setTimeout. However, the result came out as letter changing from 'a' an immediately to 'e' without displaying 'b' 'c' 'd'. However, all the letters are displayed in the console without having 1-second delay. Sorry for my confusing explanation.function changeLetter() {const symbols = ['Ai', 'a', 'b', 'c', 'd']let symbolfor (let i = 0; i < symbols.length; i++) {setTimeout(() => {symbol = symbols[i]console.log(symbol)document.getElementById("change").innerHTML = symbol;}, 1000)}}changeLetter()<h1 id="change"></h1>