javascript - 在 for 循环中逐步运行函数

标签 javascript jquery arrays for-loop

我有两个数组:ptstest。在将新对象从 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 放入其中,我看到我立即获取了从 ptstest 的所有对象。 我如何将一个对象从 pts 添加到 test 并在每次添加后运行函数 mimicSvg();

enter image description here

最佳答案

像这样使用间隔计时器:

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

关于javascript - 在 for 循环中逐步运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28131059/

相关文章:

python - 类型错误 : only size-1 arrays can be converted to Python scalars

Javascript - 对包含正数和负数 "decimal"的数组进行排序

javascript - VUE JS 在点击时将数据添加到数据绑定(bind)

javascript - 如何循环遍历字段集以检查控件是否为空或未选择值?

javascript - jQuery Post 无法在 OS X Chrome 中工作

python - 更改 python 中列表的特定元素?

javascript - jQuery 在 codeigniter 中查找 URI

javascript - 为什么不在选项卡中拉伸(stretch)我的 canvasjs 图表

javascript - Firefox 中输入数据列表的延迟加载

JAVA 数组列表 : How to know whether it contains a String array or not?