Javascript array push in a for loop -


i have 2 for loops on second 1 using push array called myarray , not pushing data has desired. returning array console in second for loop outputs following:

["scottsdale cfs"] ["scottsdale cfs", "denver cfs"] ["warren cfs"] ["warren cfs", "millford cfs"] ["rockaway cfs"] ["rockaway cfs", "border cfs"]  

however, data show this:

["scottsdale cfs", "denver cfs", "warren cfs", "millford cfs", "rockaway cfs", "border cfs"] 

how can accomplish this?

note: reason showing because iterating through json file checks through first center , retrieves data in array , goes next , same. problem arrays each have 2 elements why trying push 1 array.

var looper = function(sec0, vz, lorr) {                                      var myarray = [];         for(var i=0;i<vz[0]['areas'].length;i++){           var ttext = object.keys(vz[0]['areas'][i]);            var root = vz[0]['areas'][i][ttext][0];                                    var dataname;        }         var myarray = [];                                                                        if(sec0 === "centers") {        for(var j=0;j<root[sec0].length;j++){          var mystring = root[sec0][j]["label"];          myarray.push(mystring);           charts.chart.renderto = lorr+myarray.indexof(root[sec0][j]["label"]);            charts.title.text = root[sec0][j]["label"];         dataname = root[sec0][j]['metrics'][5]['rep res. %'].slice(0,-1);          charts.series[0].name = dataname;             charts.series[0].data = [parsefloat(dataname)];         new highcharts.chart(charts);            }                                                   }    }  } 

the reason re declaring array var myarray = [];

try following code,

var looper = function(sec0, vz, lorr) {                                     var myarray = [];      for(var i=0;i<vz[0]['areas'].length;i++){         var ttext = object.keys(vz[0]['areas'][i]);          var root = vz[0]['areas'][i][ttext][0];                                  var dataname;     }         if(sec0 === "centers") {         for(var j=0;j<root[sec0].length;j++){             var mystring = root[sec0][j]["label"];             myarray.push(mystring);             charts.chart.renderto = lorr+myarray.indexof(root[sec0][j]["label"]);                charts.title.text = root[sec0][j]["label"];             dataname = root[sec0][j]['metrics'][5]['rep res. %'].slice(0,-1);              charts.series[0].name = dataname;                 charts.series[0].data = [parsefloat(dataname)];             new highcharts.chart(charts);         }                                                 } }); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -