写一个for ... of循环 在天数组中循环遍历每一天 将当天的首字母大写 并将一天打印到控制台上
这是我编写的代码。但是没有得到想要的输出。您能帮我解决问题吗?
const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
for(let day of days){
console.log(day.charAt(0).toUpperCase());
}
答案 0 :(得分:1)
您将字符串的首字母大写:
day.charAt(0).toUpperCase()
对于sunday
,将为S
。现在,您只需连接(+
)其余字符串,在本例中为unday
。为此,您可以使用String.substr
:
day.substr(1)