I want to convert a letter in a particular index in a string to uppercase.
I have a string:
let str = "Dwightschrute";
I could do:
let str = "Dwightschrute";
let a = str.slice(0, 6);
console.log(a); //Dwight
let b = (str.slice(6, 7)).toUpperCase();
console.log(b); // S
let c = str.slice(7);
console.log(c);
console.log(a+b+c); //DwightSchrute
Or
let str = "Dwightschrute";
str = [...str];
str[6] = str[6].toUpperCase();
console.log(str.join('')); //DwightSchrute
Is there a better way to do this? I think I am doing a lot of unnecessary stuff to achieve this