我有以下字符串数组
let example = ["hello", "what"];
我想将此数组转换为此:
["Hello", "what"];
为了完成我有以下代码:
example[0][0] = example[0][0].toUpperCase();
[当我尝试console.log(示例)时,我得到了
["hello", "what"]
这里怎么了?如何将第一个元素的首字母转换为大写?
您为什么有两个方括号?您只需要一个...
example[0]=example[0].toUpperCase();
我希望能有所帮助。
let example = ["hello", "what"];
example = example.map(ar => ar[0].toUpperCase() + ar.slice(1));