作者:开在覀黎明前的小茉莉 | 来源:互联网 | 2023-05-24 14:44
我有一个包含三列的数组,如下所示:
data.push({
country: new Date(),
newSales: Math.random() * 1000,
expenses: Math.random() * 5000
});
现在,点击按钮,我想在其中添加一个新列.谁能让我知道我们怎么做?
1> 小智..:
您可以迭代数据数组并为每个元素添加键和值.
data[0]["foo"] = bar; // this can be useful if the key is not constant
要么
data[0].foo = "bar"