I currently have a function in my javascript in which I am trying to constantly push elements into an array. It looks something like this:
setInterval(function () {
var currentdate = new Date();
var datetime = currentdate.getFullYear() + "-" +
(currentdate.getMonth() + 1) + "-" +
currentdate.getDate();
var arrayofdates = [];
arrayofdates.push(datetime);
document.getElementById("demo").innerHTML = arrayofdates;
var a = (Math.random() * 100) + 1;
var b = (Math.random() * 100) + 1;
var c = (Math.random() * 100) + 1;
chart.load({
columns: [
['x', datetime],
['data1', a],
['data2', b],
['data3', c]
]
});
}, 1000);
For some reason, the arrayofdates is only stuck in one. I have checked the properties of the arraylist and even if the string is already in the list, it should still add onto the list. In this case, I am getting a string similar to 2015-08-11, but I expect the arraylist to keep on adding 2015-08-11 after every second. What am I doing wrong?? Thanks!