I have an array containing three columns like this:
data.push({
country: new Date(),
newSales: Math.random() * 1000,
expenses: Math.random() * 5000
});
Now, on button click, I want to add a new column in it. Can anyone let me know how we can do it?
You could iterate though the data array and add key & value to each element.
data[0]["foo"] = bar; // this can be useful if the key is not constant
or
data[0].foo = "bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With