Wierd things in google map javascript

I’m now implementing google map to ionic 3…
the problem is to implement marker and infowindow.

as you can see below,
once I try to implement infowindow to each of marker , it works as I intended

 this.markerStart[0].addListener('click',()=>{
             console.log('clicked')
             this.popuparray[0].open(this.map,this.markerStart[0]);
         })
         this.markerStart[1].addListener('click',()=>{
             console.log('clicked2222')
             this.popuparray[1].open(this.map,this.markerStart[1]);
         })

but I try this to just changing the way for using for loop. but it dosen’t work…

It looks exactly same…but don’t know why it dosent’ work…

//here, this.markerStart.length is 2...but it dosen't work below for loop way. 
        console.log(this.markerStart);
        console.log(this.markerStart.length);
        console.log("this.markerStart")
        for(var j=0; j<this.markerStart.length; j++){
            this.markerStart[j].addListener('click',()=>{
                console.log(j);
                //only log 2 ...which is I don't understand. why log 2?
               // j should be 0 and 1...because this.markerStart.length is 2
                this.popuparray[j].open(this.map,this.markerStart[j])
               
            })
        }
       

I tried this too

for(var j=0; j<2; j++){
            
            this.markerStart[j].addListener('click',()=>{
                console.log(j);
            })
        }

I thought once, I click first marker, It should be logged 1 and second marker it should be logged 2
but only logging 2…

You can try adding an extra property to the markers like

this.markerStart[j].id = j

and then inside the listener do

console.log(this.id)