I\'m confused with using setTimeout and the each iterator. How can I rewrite the following so that the console outputs each name after a delay of 5 seconds? Currently the
You could do
var ary = ['kevin', 'mike', 'sally']; _(ary).each(function(person, index){ setTimeout(function(){ console.log(person); }, index * 5000); });
Without increasing the timeout value, you would initialize all setTimeouts with the exact same value (thats why you see what you see).
timeout
setTimeouts