Javascript 使用.substr将第一个字母更新为大写

Javascript 使用.substr将第一个字母更新为大写,javascript,substr,uppercase,Javascript,Substr,Uppercase,我正在尝试将字符串的第一个字母更新为大写,请注意,我只允许使用.substr和.length进行转换。没有正则表达式或任何东西。 这是正确的方法/语法吗 e1 = prompt("Please enter your first name", "andrew"); e1.toUpperCase(e1.substr(e1.length - e1.length,0)); 正则表达式一切 e1 = prompt("Please enter your first name", "andrew"); e

我正在尝试将字符串的第一个字母更新为大写,请注意,我只允许使用.substr和.length进行转换。没有正则表达式或任何东西。

这是正确的方法/语法吗

e1 = prompt("Please enter your first name", "andrew");

e1.toUpperCase(e1.substr(e1.length - e1.length,0));
正则表达式一切

e1 = prompt("Please enter your first name", "andrew");
e1.replace(/^\w/, function(t){ return t.toUpperCase() })

你真的可以用谷歌来做这类事情。一般来说,不允许使用正则表达式,我只能使用类和赋值的substr/和.length部分restriction@AndrewBarsoom
e1=e1.substr(0,1.toUpperCase()+e1.substr(1)