📌  相关文章
📜  如何在 javascript 中动态地将数据添加到数组中 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:11.433000             🧑  作者: Mango

代码示例1
var lab =["1","2","3"];
var val = [42,55,51,22];
var data = [];
for(var i=0; i<4; i++)  {
    data.push({label: lab[i], value: val[i]});
}
Or an other, less concise way, but closer to your original code:

for(var i=0; i<4; i++)  {
   data[i] = {};              // creates a new object
   data[i].label = lab[i];
   data[i].value = val[i];    
}