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? -

html - Unable to style the color of bullets in a list -

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