+ 1
I want to push all click button elements into a single array.
Array adds an element by clicking the button and always shows a single element of last click. Code sample is as follow; var x; var counter=0; go=()=>{ counter++ var timer= document.getElementById("timer"); timer.innerHTML=counter } stop=()=>{ var data=[]; data.push(counter); console.log(data) } start=()=>{ var x= setInterval(go,1000) }
2 Respuestas
+ 3
make global var data = [] ;
+ 1
Thank you Igor Kostrikin , I was declearing just var data globally, now working fine by declearing whole the array.