我有两个数组:pts
和 test
。在将新对象从 pts
添加到 test
之后,我需要将 pts
中的对象一个一个地添加到 test
我需要运行函数mimicSvg
。
所以我写:
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 );
}
如您所见,我将 console.log 放入其中,我看到我立即获取了从 pts
到 test
的所有对象。
我如何将一个对象从 pts
添加到 test
并在每次添加后运行函数 mimicSvg()
;
最佳答案
像这样使用间隔计时器:
setTimeout( "mimicSvg(test,1)",m*3000 );
关于javascript - 在 for 循环中逐步运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28131059/