JavaScript How to use setTimeout with every item in an array? settimeout every second,settimeout every 5 seconds,settimeout every minute,

In the following:

ko.utils.arrayForEach(cards, function (card) {
        setTimeout(function () {
            observableData().saveCard(card);
        }, 1000);
    });

This is supposed to be waiting one second for every card in the array, but it just waits one second and then blasts through the array. How can I achieve the expected behavior?

Answer:1

You need to increment the timeouts

var idx = 1;
ko.utils.arrayForEach(cards, function (card) {
    setTimeout(function () {
        observableData().saveCard(card);
    }, (idx++) * 1000);
});

Since the arrayForEach doesn't look like giving the index of the item, you need to maintain a separate index

Answer:2

I see this code in underscore.js. Here it is, with the alias applied: toString = ObjProto.toString, However, to use toString it is also accessible directly like this, w/ out using above code at all....

I see this code in underscore.js. Here it is, with the alias applied: toString = ObjProto.toString, However, to use toString it is also accessible directly like this, w/ out using above code at all....

  1. what purpose of object bar
  2. what's the purpose of object

I want to insert new line like a following. div.row div.span12 div(ng-repeat="(data in datas)") p data.text // insert new line when $index is the number divisible by 3. how does ...

I want to insert new line like a following. div.row div.span12 div(ng-repeat="(data in datas)") p data.text // insert new line when $index is the number divisible by 3. how does ...

  1. insert line within cell excel
  2. insert line within cell
  3. insert line break within excel cell
  4. insert new line within excel cell
  5. insert line break within cell
  6. insert new line within cell
  7. sed insert within line
  8. insert bullet within line

In my web application I have edit profile page. In editprofile page their is many fields like Name : <input type="text" name="name"/> Location : <input type="text" class="...

In my web application I have edit profile page. In editprofile page their is many fields like Name : <input type="text" name="name"/> Location : <input type="text" class="...

After hacking away with DOM and event propagation issues all day I've come to the last of issues i've been trying to deal with using the marker clusterer. Currently I'm attaching a click handler to ...

After hacking away with DOM and event propagation issues all day I've come to the last of issues i've been trying to deal with using the marker clusterer. Currently I'm attaching a click handler to ...

  1. google maps marker icons
  2. google maps marker color
  3. google maps marker label
  4. google maps marker size
  5. google maps marker api
  6. google maps marker cluster
  7. google maps marker icon size
  8. google maps marker title
  9. google maps marker options
  10. google maps marker label position
  11. google maps marker tooltip
  12. google maps marker svg
  13. google maps marker click event
  14. google maps marker infowindow
  15. google maps marker images
  16. google maps marker events
  17. google maps marker style
  18. google maps marker hover
  19. google maps marker text
  20. google maps marker url