How to access javascript array values within a setinterval function

How can I access the series data from within the function defined in setinterval. When I try to access any of the values, or even the array length, it says undefined. events: { load: function() { // set up the updating of the chart each second var series0 = this.series[0]; var series1 = this.series[1]; var series2 = this.series[2]; var series3 = this.series[3]; setInterval(function() { var y = $.ajax({url: "/index.php/control/fetch/",async: false}).responseText; y = y.split(" "); var x = parseInt(y[0]); //alert("x = " + series0[0]); //alert("len is " + parseInt(series0.length)); series0.addPoint([x, parseFloat(y[1])], true, true); series1.addPoint([x, parseFloat(y[2])], true, true); series2.addPoint([x, parseFloat(y[3])], true, true); series3.addPoint([x, parseFloat(y[4])], true, true); }, 5000); } } Thanks
Can you post more code? Your code seems fine, perhaps the problem is the original assignment, i.e., var series0 = this.series[0].

以上就是How to access javascript array values within a setinterval function的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准