0

I need to write a for each loop with timer in javascript.

It will pass each index of the object with a specific time interval.
Lets say we have obj = {a:1,b:2,c:3,...}

time: 0ms => obj.a 
time: 100ms => obj.b 
time: 200ms => obj.c 
. 
. 
.

I have done the following two things but can't unite these two.

Please check out http://jsfiddle.net/WFtaG/11/

4

1 回答 1

2

用这个:

var obj = {a:1, b:2, c:5, z:12, x:0};

var timer = 0;
for (var prop in obj) (function(key, val) {
    setTimeout(function() {
        $('#curr_elem').append( key + " => " + val + " | " );
    }, timer += 1000);
})(prop, obj[prop]);
于 2012-09-24T10:34:04.520 回答