Can anyone help me with an issue I'm facing? I have a code snippet where I am trying to push a JSON Object into an array, but the array is not updating properly. It only shows the last pushed element.
var myData = {};
var id = 0;
$("a").on('click', function(){
myData.answers = new Array();
myAns = { id : id, answer : "my answer" };
myData.answers.push(myAns);
id++;
console.log(myData);
});
Check out this Fiddle link for the same scenario. Any assistance would be appreciated.