javascript - How to use setTimeout with every item in an array? -


in following:

ko.utils.arrayforeach(cards, function (card) {         settimeout(function () {             observabledata().savecard(card);         }, 1000);     }); 

this supposed waiting 1 second every card in array, waits 1 second , blasts through array. how can achieve expected behavior?

you need increment timeouts

var idx = 1; ko.utils.arrayforeach(cards, function (card) {     settimeout(function () {         observabledata().savecard(card);     }, (idx++) * 1000); }); 

since arrayforeach doesn't giving index of item, need maintain separate index


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -