I know it's easy, but I can't quite get it.
function submitNewComment() {
var noo = 0; //array index
var userName = document.getElementById('user-name').value; //textbox
var commentBox = document.getElementById('main-comment').value; //textbox
var now = new Date();
mili = now.getTime(); //time in milisecond
var element = [];
element.push({
"no": noo, //array index
"username": userName,
"date": mili,
"body": commentBox,
"likes": "0",
"parent": null
});
console.log(element);
noo++;
console.log(noo);
}
In short, I need to add create a variable as an array containing objects. When I run the function, it doesn't quite work as I hoped. I am missing something.
The problem exists when you run the function for the second time. Ideally 2nd object should be created but the first one gets updated. So, at the end of 2nd run and every other run there after, length of the array remains 1.