📌  相关文章
📜  为数组javascript代码示例中的每个对象添加值

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

代码示例1
var labels = ["DESKTOP", "MOBILE", "TABLET"];
var chartData = ["100", "10", "15"];
var myData = [];

labels.forEach(function(e, i) {
  myData.push({
    label: e,
    data: chartData[i]
  })
})

document.write(JSON.stringify(myData));