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
Post a Comment