I have a challenge in looping through an array where I want to output each value of the array with a delay. My current understanding is as follows:
UPDATE
Check out the JS Fiddle for reference: http://jsfiddle.net/d3whkjww/
loopThroughSplittedText: function(splittedText) {
for (var i = 0; i < splittedText.length; i++) {
// console.log a word in each iteration
// pause after each one
setTimeout(function() {
console.log(splittedText[i]);
}, 1000);
};
},
However, this code is not functioning as expected. I suspect that the arguments in the "for" loop need to be handled differently within the setTimeout function. Unfortunately, I am unsure how to rectify this issue.
Currently, all values in the array are displayed at once instead of appearing with a delay. How can I accomplish this?