You have to actually re-assign the array element:
for(var i = 1 ; i < newArr.length ; i++){
newArr[i] = newArr[i].charAt(0).toUpperCase();
}
The "toUpperCase()" function returns the new string but does not modify the original.
You might want to check to make sure that newArr[i]
is the empty string first, in case you get an input string with two consecutive dashes.
edit — noted SO contributor @lonesomeday correctly points out that you also need to glue the rest of each string back on:
newArr[i] = newArr[i].charAt(0).toUpperCase() + newArr[i].substr(1);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…