This is related to the arrays in Javascript, which I am trying to use in a complex logic.
Consider the following code:
a['a1'] = 'AJA'
We know that, this is same as a.a1 = 'AJA'
(provided proper definitions were given).
So, if we go ahead and interpret this:
console.log(a.a1[0])
console.log(a.a1[1])
console.log(a.a1[2])
console.log(a.a1)
It logs :
A
J
A
AJA
Now, all I need is to assign a new character at the 4th position.
When I try a[a1][3] = 'Y'
or a.a1[3] = 'Y'
and then try console.log(a.a1)
, It still displays AJA
instead of AJAY
.
I know that we can do this using string concatenation, i.e.
a['a1'] = a['a1'] + 'Y'
and get this accomplished.
But why wasn't the first method working? By what other ways can do this?