+ 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) }

5th Jun 2020, 11:17 AM
Tahir Usman
Tahir Usman - avatar
2 Antworten
+ 3
make global var data = [] ;
5th Jun 2020, 12:27 PM
Igor Kostrikin
Igor Kostrikin - avatar
+ 1
Thank you Igor Kostrikin , I was declearing just var data globally, now working fine by declearing whole the array.
6th Jun 2020, 1:24 AM
Tahir Usman
Tahir Usman - avatar