Dynamic variable in javascript push function

后端 未结 1 1364
甜味超标
甜味超标 2021-01-27 08:55

I\'m using push function in javascript.

var chartData = [];
for(var i=0; i<3; i++) {

    chartData.push({

        date: new Date(year_s,mon_s,date_s,hr_s,mi         


        
1条回答
  •  温柔的废话
    2021-01-27 08:58

    You have to make it in two steps :

    var chartData = [];
    for(var i=0; i<3; i++) {
       // 1. create the object
       var d =  { 
          date: new Date(year_s,mon_s,date_s,hr_s,min_s,sec_s),
          customBullet: show_annotations,
          balloonTextField: "testtesttest"
       };
       // 2. then assign the visits_i property
       d['visits_'+i] = chartData1[selection[i]][j].value; 
       chartData.push(d);
    }
    

    0 讨论(0)
提交回复
热议问题