Returning first letter of index in array to uppercase. What am I doing wrong here?

Returning first letter of index in array to uppercase. What am I doing wrong here?
0

#1

Beginner here working my way through the ‘Basic Algorithm Scripting’ section of FCC. This question relates to ‘Basic Algorithm Scripting: Title Case a Sentence’ but indirectly.

Would someone please explain to me my misunderstanding here?

I would expect the following code to produce arr = [‘Red’,‘blue’,‘green’]

let arr = [‘red’,‘blue’,‘green’];
arr[0][0] = arr[0][0].toUpperCase();

console.log(arr);

But this outputs: ‘red’,‘blue’,‘green’

I have a feeling it has something to do with strings vs. arrays but i’m not really sure.

Also what is the code that would produce arr = [‘Red’,‘blue’,‘green’]?

Thanks in advance!


#2

Strings are immutable, you can’t mutate characters in the string. You would normally take your string, copy the first letter and uppercase it, and join that to a copy of the rest of the string.