//将一句英文的首字母转大写,其它转小写
var word='Welcome to my little WORLd. I have a DREAM thAt iS TO fLy to tLe sky';
//字符串拆分为数组
var a=word.split(' ');
for(var i=0;i
//var str1=a[i].slice(0,1).toUpperCase();
var str1=a[i].substring(0,1).toUpperCase();
//其余字母小写
//var str2=a[i].slice(1).toLowerCase();
var str2=a[i].substring(1).toLowerCase();
//字符串拼接后,把转换结果替换之前的
a[i]=str1+str2;
}
//数组转字符串
console.log(a.join(' '));