Help! TypeError: Cannot assign to read only property of '0' in string

Hey folks! Can someone please explain to me why I can’t seem to use bracket notation to alter the first character of each item in an array? Everything works fine if if I try:

var a[i] = a[i].toUpperCase():
var a[i] = a[i][0].toUpperCase();

but as soon as I try to modify var a[i], it yells at me, saying it cannot read only property of ‘x’. Please help me understand why!

(Please note: I’m not asking for the answer to this challenge, if you recognize it. I’m simply wondering why I cannot use bracket notation in this way)

I don’t think a variable name can contain brackets. What you are doing here is very bizarre. I have never seen a variable name with brackets - that’s just not how JavaScript works. Bracket notation can be used on the right side of the assignment operator (=) but not on the left side of it. You should review the basics of variable names.

1 Like

Hint: try replacing the entire string (a[i]) with its first character in upper case concatenated together with a slice of the rest of it in lower case.


Thank you so much for this answer! I was bashing my head into the keyboard over this.