I need to assign a variable the following:
ref => { this.marker = ref}
This is happening in a loop and i need this.marker
to be named like this.marker + i
, so i can set and access this.marker1
, this.marker2
etc..
Is this possible?
I need to assign a variable the following:
ref => { this.marker = ref}
This is happening in a loop and i need this.marker
to be named like this.marker + i
, so i can set and access this.marker1
, this.marker2
etc..
Is this possible?
You need to index into the object by string:
this['marker' + i] = ref
In Javascript, a.b
and a['b']
are the same, except that in the latter, 'b'
can be replaced with any expression that results in a string (or indeed any value that Javascript is willing to treat as a string, which is anything at all).
That said, you might be better off with an array depending on your use case.