dert detg
dert detg

Reputation: 303

Run function by step inside for loop

I have two arrays: pts and test. I need to add objects from pts to test one by one, after adding new object from pts to test I need to run function mimicSvg.

So I write:

var test=[{"X":"300","Y":"400"}];
for(var m=1;m<pts.length;m++){

    var q = pts[m].X;
    var e = pts[m].Y;
    console.log(test);
    test.push({"X":q,"Y":e});
    alert(m);
setTimeout( "mimicSvg(test,1)",3000 );    
  }

as you can see I put console.log into this and I see that I get all objects from pts to test at once. How I can add one by one object from pts to test and after each adding to run function mimicSvg();

enter image description here

Upvotes: 1

Views: 56

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85573

Use interval timer like this:

setTimeout( "mimicSvg(test,1)",m*3000 );

Upvotes: 2

Related Questions