Answer by Nasser Torabzade for Array resets after push

You should call push() inside your click() event to make it run on every click:

$(document).ready(function(){
    if(typeof arr == "undefined"){
        var arr = new Array();
    }

    $("#submit").click(function(){
       arr.push(2);
       console.log(arr);
    });
});

Leave a Reply

Your email address will not be published. Required fields are marked *