I want to iterate an array in Javascript and one element will take some time to get processed.
I want to till that element is processed, wait for that.
var splittedText = ["Hello", "World", "How", "Are", "You", "Today"];
var text = "";
splittedText.forEach((name) => {
if (name === "Are") {
setTimeout(() => {
text = text + "ARE"
}, 2000)
} else {
text = text + name + " ";
}
console.log(text)
});
Expected Output - Hello World How ARE You Today.
Actual - Hello World How You Today